Issues with @react-spring/web and React 18 in strict mode
#68141
Unanswered
milotoor
asked this question in
App Router
Replies: 1 comment
-
|
Any update about this ? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've encountered some odd behavior related to
@react-spring/web(via the@mui/x-chartspackage which uses it) that I've so far only been able to reproduce within the context of the Next.js App Router. I'm not sure if this is a bug with the App Router or not; this post is intended mainly to improve my understanding of what "strict mode" means in the context of the App Router, and whether Next.js applies any significance to<StrictMode>beyond React's own implementation.Consider the following code:
This is a very simple usage of the
useSpring"flagship hook" from@react-spring/web. It renders ansvgand within it a short bluerectwhich initially has zero width but soon grows to a width of 300px. You can see it in action here. React's "strict mode" is in effect.That's all well and good. However, when I port the exact same code into the Next.js v14 App Router, things begin to break down. Consider the following setup:
Items to note:
reactStrictModeis set to false. This turns off strict mode globally and is crucial for demonstrating the purported buguse clientdirective. This is needed becauseuseSpringrelies onReact.createContext<Demo>component is rendered twice withinPage, once within a<StrictMode>boundary and once without itSee this sandbox for a live example. This code misbehaves. The expected behavior is that two
svg's should render, each with its own bluerectthat grows to 300px wide. However, only the firstDemocomponent (i.e. the one outside of<StrictMode>) achieves this. The secondDemorenders ansvgand arect, but its width is stuck at 0 forever.I'm having a very hard time understanding why the behavior of these two snippets differs. They both render the exact same
Democomponent wrapped in aStrictModeboundary, yet in the context of the Next.js App Router this fails to achieve the desired result. I have virtually no familiarity with Next.js internals, and I'm hoping someone here will have some clue or hunches about what might be going on.Thanks in advance for any ideas!
Beta Was this translation helpful? Give feedback.
All reactions