-
Notifications
You must be signed in to change notification settings - Fork 27k
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
_document -> makeStylesheetInert -> "Cannot read property 'type' of null" if Child is null #24783
Comments
Can you elaborate why you're rendering a NullComponent in Head? Head should contain regular head-elements such as link, script, meta, not nothing. |
for example when you write something like that:
if condition is false you get the error! |
now I solved it this way:
but a nullsafe in that point is a better and safer solution! |
agreed, I'll try to PR this later today |
EDIT: Still a bit related to the original issue. accessing props maybe needs more sanity checks? (nullsafe, readonly...) EDIT#2: I'm having a somewhat similar issue: next.js/packages/next/pages/_document.tsx Line 340 in cf4ba8d
nextjs 10.2.0 Still trying to figure out the root cause though. |
@pecoram could you try to create a reproducible repo? Both import Head from "next/head";
export default function Test() {
return (
<>
<Head>{false && <link rel="preload" as="image" href="" />}</Head>
<h1>hi</h1>
</>
);
} and import Head from "next/head";
export default function Test() {
return (
<>
<Head>{null}</Head>
<h1>hi</h1>
</>
);
} work flawlessly for me @synoptase same for you please, import Head from "next/head";
export default function Test() {
return (
<>
<Head>
{/* // eslint-disable-next-line react/jsx-no-useless-fragment */}
<>{null}</>
</Head>
<h1>hi</h1>
</>
);
} works fine too |
@ljosberinn it worked indeed in my dev env. But once build and deployed, error kept appearing until i removed Not a bug as initially reported by my first comment then. |
This is a bug, it's related to the new font optimization (which only runs during build). |
I believe changing the implementation of makeStylesheetInert(node: ReactNode): ReactNode[] {
return React.Children.map(node, (child) => {
if (!React.isValidElement(child)) {
return null
}
if (
child.type === 'link' &&
child.props.href &&
OPTIMIZED_FONT_PROVIDERS.some((url) => child.props.href.startsWith(url))
) {
return React.cloneElement(child, {
...child.props,
'data-href': child.props.href,
href: undefined,
})
}
if (child.props?.children) {
return React.cloneElement(child, {
...child.props,
children: this.makeStylesheetInert(child.props.children),
})
}
return child
})
} |
I'm also experiencing a similar problem: Error message: But in my case, this is the line inside the
It wasn't failing in Next.js 10.0.6. |
I'm having a hard time reproducing this bug. We also already check for this edge case Could you make a small example where the error is reproducible? |
Maybe there's two bugs here, but I get this error message with |
Our project suddenly started returning 500s in production because of I've created a project where I've reproduced the issue (https://github.com/atdrago/repro-24783). Here's the commit where the issue is introduced: atdrago/repro-24783@1ea71f6 Steps to reproduce:
Some things I noticed:
Node.js: 14.15.0 Please let me know if you have any questions, and thank you for your time and effort looking into this issue! I've created a related issue on |
It's fixed in next-boost itself in v0.10.2. |
x-ref: #28498, #31784 I can repro the issue #24783 with `next-boost` 0.10.1 and it was fixed in 0.10.2 (ref: next-boost/next-boost@eba6d10). The actual case is missing setting node env to `"production"`. React freeze element props and element itself in dev mode (ref: https://github.com/facebook/react/blob/a724a3b578dce77d427bef313102a4d0e978d9b4/packages/react/src/ReactElement.js#L194-L196) Then next.js will reassign props with react development bundle while next-boost is enabled. Those operations are only happened in non-dev mode so it's good to remove now. This PR + #31898 == revert #31784 cc @styfle @awareness481
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. |
What version of Next.js are you using?
10.2.0
What version of Node.js are you using?
14.16.0
What browser are you using?
All
What operating system are you using?
Windows
How are you deploying your application?
Other platform
Describe the Bug
When a Child of the Head is null an exception is thrown:
TypeError: Cannot read property 'type' of null
.In the condition a nullsafe is missing
next.js/packages/next/pages/_document.tsx
Line 331 in cf4ba8d
Expected Behavior
To Reproduce
In the _document put a null component inside the Head.
The text was updated successfully, but these errors were encountered: