-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Possible MetaFunction bug #7584
Comments
Are you using React canary? |
No. The stackblitz example is using react 18.2.0 |
I think you're correct in that the mutation is causing the issue, so subsequent renders don't pick up on tagName. I think we can just change it to just destructure off the if ("tagName" in metaProps) {
let { tagName, ...rest } = metaProps;
if (!isValidMetaTag(tagName)) {
console.warn(
`A meta object uses an invalid tagName: ${tagName}. Expected either 'link' or 'meta'`
);
return null;
}
let Comp = tagName;
return <Comp key={JSON.stringify(rest)} {...rest} />;
} I'll try to get a fix in for this soon 👍 |
That's great to hear! If you have have time, I am also curious if it was anything wrong with my test file: https://github.com/ErlendS/remix-possible-metafunction-bug/blob/main/integration/bug-report-test.ts. It should be the exact same example as the one shared in Stackblitz, but it passes the test. |
Thanks for looking into this @brophdawg11 and @ErlendS, I am having this issue too. |
This is resolved by #7594 and will be included in the next release 👍 |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
What version of Remix are you using?
2.0.1
Are all your remix dependencies & dev-dependencies using the same version?
Steps to Reproduce
The problem:
When passing the meta function an array for it to return, and one of the objects in the array has the property: "tagName: 'link'", it causes an hydration error.
Steps to Reproduce
I tried creating a fork with a test to produce the bug: https://github.com/ErlendS/remix-possible-metafunction-bug/blob/main/integration/bug-report-test.ts
But the test passes...
However, when I created (what I believe to be) the exact same setup in stackblitz, the error appears:
https://stackblitz.com/edit/remix-run-remix-rvjcj7?file=app%2Froutes%2F_index.tsx
How to see the error:
It should give out a warning like :
Warning: Expected server HTML to contain a matching <meta> in <head>.
If you then go to the 'Network' tab and view the response from the document being returned by Remix, the
<head>
should contain<link rel="icon" href="https://remix.run/favicon-32.png" type="image/png"/>
.Continue to the 'Elements' tab and check the
<head>
in the document and you will see it is incorrectly rendering:<meta rel="icon" href="https://remix.run/favicon-32.png" type="image/png">
The server and client have mismatching tags.
Additional info:
I hope you don't mind, but since its not much code I thought I could add the code here to make it easier to view :
Looking a bit in the Remix code, I think this might be the issue:
remix/packages/remix-react/components.tsx
Line 516 in a20ae7f
it could be when "tagName" is deleted, the reference object is mutated, therefore when the meta function runs again on the client it assigns the object as a meta tag.
And if this is the cause, it could possibly be fixed a few lines above: https://github.com/remix-run/remix/blob/a20ae7fb0727212ac52bdc687513c61851ac4014/packages/remix-react/components.tsx#L509C25-L509C34
by cloning the object so it doesn't point to the same object in memory.
Expected Behavior
When the meta function receives the array it should return as a prop, and one of the objects in the array has the property: "tagName: 'link'", we should not get a hydration error. It should render a
<link>
tag on the server and on the client.Actual Behavior
The Meta component returns a
<link> tag on the server and <meta> on the client.
The text was updated successfully, but these errors were encountered: