-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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
Next 13 throws when useLayoutEffect is imported, even if it's not possible for it to run #49714
Comments
Possible related to #49355 |
Related to vercel/swr#2632 |
import { useLayoutEffect } from 'react'
function Foo() {
useLayoutEffect()
}
function Page() {
return cond ? <Foo/> : null
} This will error even if There're two workarounds, one is to use |
If it helps, this particular case seems to be from the @xstate/react library invoking If the built-in Does it seem a bit unusual that a dependency using React's official shim for a method that is supported in server rendering would cause Next to throw? |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.3.0: Thu Jan 5 20:48:54 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T6000 Binaries: Node: 16.14.0 npm: 8.3.1 Yarn: N/A pnpm: N/A Relevant packages: next: 13.4.3-canary.0 eslint-config-next: 13.4.1 react: 18.2.0 react-dom: 18.2.0 typescript: 5.0.3
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue
https://codesandbox.io/p/sandbox/confident-meadow-tugfro
To Reproduce
Install and run the provided CodeSandbox example.
Describe the Bug
When I import a library that contains components that use
useLayoutEffect
as well as other non-component code in order to call a non-component function in the app/layout.tsx file, Next throws merely becauseuseLayoutEffect
was imported, even though it's not called - and not even possible to use, because the imported function is run outside a render function.Expected Behavior
It should only throw if we try to actually call
useLayoutEffect
on the server. It should not throw merely becauseuseLayoutEffect
is imported somewhere in a library. (I believe this was the Next 12 behavior.)Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: