-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
NextJS SSR: Prop type do not match when mapping components from array #2134
Comments
I also tried this on my separate computer, this time a Macbook Pro. |
Thank you for the report - this issue only affects a dev environment (so that's at least some upside of this). I'm looking into resolving it holistically. |
I've prepared a PR that aims to fix this once and for all: #2136 🤞 |
I tested your branch in my project and it works in Firefox, but I have noticed another similar problem.
I have yet to identify exactly what is causing this issue. Once I figure it out, I will update the repository for you! |
I have now updated the repo with the new issue. // It seems like having a forwardRef with displayName causes the mismatch.
const Button = React.forwardRef(({ children }, ref) => {
return <button css={{ background: "red" }}>{children}</button>;
});
Button.displayName = "Button"; Removing either the According to https://reactjs.org/docs/forwarding-refs.html#displaying-a-custom-name-in-devtools, it seems you are supposed to pass a named function if you want the name to be correct. const Button = React.forwardRef(function Button({ children }, ref) {
return <button css={{ background: "red" }}>{children}</button>;
}); |
Changing the regex to this seems to have solved the issue for me: let match = error.stack.match(
/(^.+)\n.*(renderWithHooks|finishClassComponent|processChild|ReactDOMServerRenderer.render)/m
) Tested in both Chrome and Firefox. Update: Seems like it's not as simple as that. When using forwardRef without a named function or with The second example (see above) using named function works in both Chrome and Firefox. I am unsure if setting |
Thank you for double-checking my efforts! You have certainly uncovered some nice scenarios to test here:
I will give this more thought to figure out the best solution that covers all those scenarios. |
@Andarist I am running into the same issue with NextJS 13, React 18 and forwardRef in Chrome. |
Current behavior:
When using the
css
prop on elements that are mapped from an array, the following error shows up in Firefox but not in Chrome:Here is the code that causes the problems:
To reproduce:
I cannot reproduce this in a CodeSandbox since this is dependent on NextJS SSR capabilities.
However, I have set up a clean repository to reproduce the issue, with only the required dependencies.
https://github.com/AlexanderArvidsson/emotion-bug-ssr
Please take a look at the top of the component in
pages/index.tsx
.The repository is not using TypeScript, but I am having the exact same problem in my TypeScript project. Only difference is that it is using twin.macro, TailwindCSS and emotion. Should not matter though since I reproduced the issue without any of those packages.
Keep in mind that this issue only occurs in Firefox for me.
I've read around and found a couple of issues, some related to styled-components, some with ThemeUI.
The closes issue I found was #1462 (comment) and system-ui/theme-ui#538 (comment) but it did not help me resolve the issue.
Interestingly enough, it does not seem to happen after a production deployment to Vercel: https://bug-ssr.vercel.app/
Expected behavior:
The property should match after hydrating.
Environment information:
NextJS
version: 10.0.3react
version: 17.0.1@emotion/react
version: 11.1.1The text was updated successfully, but these errors were encountered: