Closed coreyasmith closed 3 months ago
Hi @coreyasmith -
This is a known issue since Sitecore JSS Next.js SDK was introduced (v16). We have it in our backlog to revisit in the near-term; however, it has been a low priority as it does not impact content editing (and it only occurs for next:dev, not production).
Please feel free to re-open if this is impacting the actual content editing.
@ambrauer Next.js only displays one hydration error mismatch at a time, so although this phkey
warning does not cause issues, it hides other issues in our own app that are causing issues in the Experience Editor.
I believe that this is the source of the error: https://github.com/Sitecore/jss/blob/b006d3d34a59606d59fdde67f73f2867c75f5397/packages/sitecore-jss-nextjs/src/editing/editing-render-middleware.ts#L155
During SSR, EditingRenderMiddleware
is rewriting the phkey
attribute that is added to placeholder raw components by PlaceholderCommon
to key
. This upsets Next.js because it expects those raw components to be rendered as <code phkey="some-key" />
during SSR, but instead they're rendered as <code key="some-key" />
due to the EditingRenderMiddleware
rewrite.
I fixed this warning by changing the EditingRenderMiddleware
rewrite to preserve the phkey
attribute when it adds the key
attribute:
html = html.replace(new RegExp(/(phKey="[^"]+")/, 'g'), '$1 key=$1');
So during SSR <code phkey="some-key" />
becomes <code phkey="some-key" key="some-key" />
and Next.js doesn't seem to mind.
With this issue fixed, we get some new hydration warnings from the <Placeholder />
component we didn't see before:
I've not tested the fix above much, but I think it's a good starting point to look into this issue.
I'm not able to re-open this issue but I'm happy to open another one if you'd like.
@coreyasmith I'm re-opening for visibility (my bad) until we come up with a proper fix.
I've bumped this one in our backlog since, based on your findings, it appears this issue may be masking others.
Thanks once again for the detailed response, we appreciate it :)
This has been automatically marked as stale because it has not had recent activity. It will be closed if there is no further activity within 30 days. You may add comments or the 'keep' label to prevent it from closing. Thank you for your contributions.
Describe the Bug
The following warning is shown in the browser console in the Experience Editor:
To Reproduce
Expected Behavior
No hydration warnings are thrown in the Experience Editor with a fresh install.
Possible Fix
No response
Provide environment information