-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
heads up, latest preact-x with compat with next.js latest canary - infinite loop at app load #2610
Comments
Hey @srdjan thanks for opening this issue. I'm trying to narrow it down but I failed. Can you share a repo/codesandbox with the above issue? |
We'd love to take a look at this but needs a reproduction case. Can you share a codesandbox or a repo where the issue can be reproduced? |
I created a reproduction link over at: https://codesandbox.io/s/wild-microservice-7z30n?runonclick=1 - not sure if I managed getting codesandbox to install canary-versions of Next though. I think it "works" (breaks) as expected. Running the example crashes the tab. I did some digging and found what I think is the issue. In canary-28, the Link component was converted to a function component, and in the Material UI example (which is what I'm using in my project) this updated link component gets sent as a reference to the MUI "link" component to be rendered inside their link component (for styling). Something with the references is causing an infinite loop(?). Pull that was merged is at vercel/next.js#14633 This wrapping component that the MUI example uses is inside the example as well, |
link to repository with reproduction: |
Awesome thank you so much to you both for the reproductions! You two rock 🙌 Can't stress enough how much this makes it easier for us to fix bugs 💯 |
Just like @marvinhagemeister said! 😃 It's something related to Looking into it more. |
I'm thinking this might be caused by Next manually invoking Or, it's the ref->state loop they have (I'm paraphrasing): function Link(props) {
const [childElm, setChildElm] = useState();
const child = Children.only(props.children);
const childProps = {
ref: (el) => {
setChildElm(el)
}
};
return React.cloneElement(child, childProps);
} For some reason we are re-calling Another thing I wanted to point out - it seems like this is only happening during development? Maybe something we're doing in the debug add-on is triggering type changes that cause the ref to be re-invoked every time? (purely a guess) |
I get that infinite loop reproducing on production build as well. Not happening with react so I'll take your pointers and dig more in a few. Thanks @developit for weigh in on this one 👍 |
I wonder if it's a memoization bail-out? Next uses They're passing a new
Batching prevents
I believe React uses a "settling" logic to drop repeated hook changes, whereas we use referential equality. Here, it seems like that breaks. |
Alrighty, @developit was totally correct that was the issue. He opened up a PR against |
The Next.js fix was landed in [email protected]. @srdjan if you're able to update, would love to know if that fixed it for you. |
yes, that. fixed it for me! |
Reproduction
using-preact next.js example with latest next canary and latest preact
Steps to reproduce
infinite loop at app start time, error:
Script terminated by timeout at:
preact__WEBPACK_IMPORTED_MODULE_0__.options.b@webpack-internal:///./node_modules/preact/debug/dist/debug.module.js:5:5986
preact__WEBPACK_IMPORTED_MODULE_1.options.b@webpack-internal:///./node_modules/preact/compat/dist/compat.module.js:54:1062
T@webpack-internal:///./node_modules/preact/dist/preact.module.js:15:4554
g@webpack-internal:///./node_modules/preact/dist/preact.module.js:15:2155
T@webpack-internal:///./node_modules/preact/dist/preact.module.js:15:5984
m/<@webpack-internal:///./node_modules/preact/dist/preact.module.js:15:1509
m@webpack-internal:///./node_modules/preact/dist/preact.module.js:15:1409
preact__WEBPACK_IMPORTED_MODULE_0.options.debounceRendering/<@webpack-internal:///./node_modules/@prefresh/core/src/runtime/debounceRendering.js:16:4
debug.module.js:1:4896
The text was updated successfully, but these errors were encountered: