-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Failed to execute 'createElement' on 'Document' | v9.5.4 #17721
Comments
Also having this issue when trying pass a component into the |
Yeh this is a catch22 because we can't apply the open redirect security patch due to this major bug. Site doesn't function based on our use of scripts and other functionality that is required in the Any suggestions on how to work around this issue until it's fixed? Here's an example of how we use it:
resulting in functionality issues per the runtime error. It "silently" fails in prod, meaning the page may still render depending on the Head implementation, but it completely kills dev environment per OP. |
My understanding of the issue is this change and/or this change removed support for accepting react components as a type, whether said component is simply
Running forked version of nextjs locally: I wonder if the problem is the difference between what |
Upgrading to the last version we notice the same problem in our project, for example with <Head>
<title>Page title</title>
... etc
<ResourceHints />
</Head>
if there the plan is remove array/react elements support in the head that change I think should be a major version, otherwise it's a bug, btw only happens us in dev mode |
@vxcamiloxv at least for us, it happens in all environments (prod vs dev), it's just dev actually throws the error and kills dev environment (for us). Prod fails silently, still throwing an error in console, but it doesn't kill the site. If you look at your HTML markup, whatever was in your react component within |
According to one of the maintainers, it's by happy accident that this ever worked. Don't think they realized they were supporting this "feature" ;) |
@jflayhart in our case we just called a function that returns an array of
instead of:
That fixed our problem on dev build and removed the error on console in production. Maybe that could help, in some cases. |
And this is documented https://nextjs.org/docs/api-reference/next/head |
@timneutkens according with the link so react components inside Head are supported according with that |
I'm using the |
It says this is supported:
And this:
I'm saying it definitely did not work as you would expect on client-side navigation if it was rendered inside of However that is not how next-seo works afaik, it renders a list of tags, not a React component. And uses |
Just created a small app to verify what I've been saying:
To further confirm this I went and added another tag as This was tested on Overall we can bring the behavior that is currently there back, @jflayhart did some work for that in #17770. However that is not ideal obviously as you currently don't get Update: just checked the array list method (which next-seo uses) too and it seems that this has the same behavior as having a React component in |
Yeh that makes alot of sense now, @timneutkens. Thanks for that example app.
Agreed, and I made changes to my PR based on your valid concerns. I hope my PR gets us to where we all want to be, especially now that I am less ignorant of the docs and more aware of the intentions behind |
I was discussing this with @devknoll (who opened #17920 after I talked to him). He made the very relevant point that if we fix the issue + render the head correctly on client-side navigation it'll actually further break apps that relied on the behavior we had in previous versions. E.g. what if they're injecting Even though not 100% ideal probably the best way to go would be to bring back the previous behavior and then introduce warnings at some point. |
@timneutkens Makes sense. I tested #17920 and it filters out the Although, I am confused with this statement here:
Are you saying that people have figured out that components in EDIT: My point being if people are doing things the way React allows, this shouldn't be much of a breaking change, but I am likely missing something since I don't have as much insight into next/head. |
The concern is that both are breaking changes. The I think we should fix it but:
|
There’s still a problem that #17920 doesn’t fix: non-title elements rendered by custom components will be orphaned, where previously they would just be deleted when Next initialized. I’m not sure yet how that should be addressed. |
Closing the loop here for some that may come across this thread, I was incorrectly using Bad, also breaks on 9.5.4 <>
<Head>
<NextSeo {...} />
</Head>
<main>
<MyApp {...} />
</main>
</> Good, works on 9.5.4 <>
<NextSeo {...} />
<main>
<MyApp {...} />
</main>
</> |
For our e-commerce app we were lucky since we were already using stateless, functional components within ℹ️ As the docs say, you MUST have it as direct children of Head, or wrapped at maximum in one level of I think it's safe to say this won't be supported soon (as it officially never was), but the maintainers are aware it's desired and I bet it will be supported in some major version based on breaking changes. For now, functions that return Fragment or array work! Sorry to anyone who has to refactor their class components, but at the same time it's only some meta/link tags. P.S. At this point, @timneutkens I think we can probably call this out as a leaky bug, but hopefully support this as a react-ish feature eventually. You all will decide and make the right decision, thanks! |
@timneutkens But how come
EDIT: I guess the docs are saying it is literally rendered as raw head html, so it works seamlessly with JSX?
My my... can learn a lot from re-reading documentation 😉 |
Because |
As another call out, for any of those who use a custom server, you could just write some express middleware to fix the security issue to properly sanitize or 404 the open redirect bug. Just saying so no one feels 100% stuck between a rock and a hard place. |
For me this only occurred while using Next-Seo library like this:
But now taking it out from the Head element, it works while still remaining inside the page head.
I guess this work since BreadcrumbJsonLd returns a <script> element and not a Head. I could be wrong. |
I had the same issue as described above with my photography website and was able to make a workaround fix thing for my use case. The PR I created is here and this contains a diff of the changes. A description of what I did is as follows:
After all that, I was able to get things working and reach full test coverage once again. Hope this helps someone else. An interesting challenge to solve! |
@jflayhart 100%! I was struggling with this and switching to calling as "functional" |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
I ran into this error after updating Next.js to version 9.5.4. The problem is that you cannot use React Components inside
Head
in _app.js file.Minimal Example:
To Reproduce
Just open the dev server
Reproduction repo: next-bug-report
Screenshots
System information
The text was updated successfully, but these errors were encountered: