You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot read properties of null (reading 'children') - dynamicCSS.ts #603
Hi there, thank you for authoring these utilities.
We have run into a persistent problem when hydrating server-side-rendered react using cssinjs-based components (eg antd-v5) due to the following calls in dynamicCSS.ts.
When hydrating an SSR react app, if there is a mismatch between the client-render and server-render then the client will re-render the component. For frameworks like remix, where the whole document is rendered, document.querySelector('head') and document.body may both be null at the time of rendering, leading to the following error
Uncaught TypeError: Cannot read properties of null (reading 'children')
I believe the following PR, which has already been open for quite some time, will address the bug. So we would like to request considering it for merge. Thank you in advance!
After hydration mismatch, when the react tries to switch to client rendering, sometimes document is blank and accessing children causes entire app to break and can't be restored.
A user needs to hard refresh the page to recover. @zombieJ, there is an open pull request (> 1 year) #455 which should be merged.
as of now, monkeypatch of @ethos-seth is the only solution.
I've also run into this issue and do some analysis.
The problem seems to stem from @ant-design/cssinjs, specifically within the useCacheToken hook. This hook utilizes useGlobalCache to inject CSS styles into the document's <head> (via rc-util's updateCSS function). Crucially, useGlobalCache relies on the useInsertionEffect React hook to perform this operation.
However, when using Remix or React Router v7, useInsertionEffect appears to fire prematurely for reasons I haven't yet identified. It executes before the DOM is fully constructed, at a moment when document.head does not yet exist. This causes the updateCSS function to throw an error, as it cannot find the <head> element to append the style tag to. At this point, only a hard refresh resolves the problem.
On a positive note, I recently discovered that after upgrading react and react-dom to 19.1.0, useInsertionEffect seems to behave as expected. It now fires at the correct time, after the document.head is available in the DOM. This prevents the updateCSS error from occurring and completely resolves the issue.
Activity
[-]children is not a property of null[/-][+]Cannot read properties of null (reading 'children') - dynamicCSS.ts[/+]josepdaniel commentedon Dec 11, 2024
Here are some downstream issues we've found on GH which appear relevant
0xNoWater commentedon Jan 11, 2025
omfg. This issue has been plaguing me! It took me a while to realize it was happening down in rc-util. Thanks for filing this!
An ~18 month old open PR doesn't feel particularly promising. Is there any way to get this merged?
Also @josepdaniel have you found any workarounds?
Edit: For now my solution is a monkeypatch:
divyeshsachan commentedon Jan 27, 2025
After hydration mismatch, when the react tries to switch to client rendering, sometimes document is blank and accessing children causes entire app to break and can't be restored.
A user needs to hard refresh the page to recover.
@zombieJ, there is an open pull request (> 1 year) #455 which should be merged.
as of now, monkeypatch of @ethos-seth is the only solution.
althafdemiandra commentedon Apr 9, 2025
bumping this as in react-routerv7
arthurvaverko commentedon Sep 7, 2025
Same issue, react router 7 with Antd .. trying the monkey patch really waiting for an official fix
hongfanmeng commentedon Sep 15, 2025
I've also run into this issue and do some analysis.
The problem seems to stem from
@ant-design/cssinjs, specifically within theuseCacheTokenhook. This hook utilizesuseGlobalCacheto inject CSS styles into the document's<head>(viarc-util'supdateCSSfunction). Crucially,useGlobalCacherelies on theuseInsertionEffectReact hook to perform this operation.However, when using Remix or React Router v7,
useInsertionEffectappears to fire prematurely for reasons I haven't yet identified. It executes before the DOM is fully constructed, at a moment whendocument.headdoes not yet exist. This causes theupdateCSSfunction to throw an error, as it cannot find the<head>element to append the style tag to. At this point, only a hard refresh resolves the problem.On a positive note, I recently discovered that after upgrading
reactandreact-domto19.1.0,useInsertionEffectseems to behave as expected. It now fires at the correct time, after thedocument.headis available in the DOM. This prevents theupdateCSSerror from occurring and completely resolves the issue.