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
bug: Next.js 13 custom server + SSR + Hydration #4389
I have searched for existing issues that already report this problem, without success.
Stencil Version
3.2.2
Current Behavior
This is a extension from the Stencil Discord thread, where a issue was asked to log an issue that can replicate the issues my team is seeing while trying to use NextJS 13.4+ with Stencil 3.3.2 and hydrate renderToString with a custom server to provide the server with a hydrated document.
Example screenshot
Expected Behavior
I expect the server and client to be in sync from an initial render, with the expectation that fetching and interactive elements won't be available
Seems to be fixed. I'd love to get that PR merged one day.
Appreciate it would be quite the undertaking at this stage but I'm still around and willing to make it happen :)
We have full SSR and Stencil/NextJS running by using JohnJenkins 2.23 build with the integrated PR (for most of the slot problems) and we hydrate Stencil before NextJS, by putting defineCustomElements in a beforeInteractive Script or a plain old <script> with dangerouslySetInnerHTML in the _document page.
Also be sure to set <body style={{ display: "block" }}> as NextJS has the body hidden until NextJS is initialized in dev mode, causing problems if components use componentDidLoad and calculate some height/width there.
Can any of you help me? I have my company’s design system that is using the stencil and they work perfectly in the next version that uses the pages/ folder, but trying to use it in the app/ folder in the new 13.4 version the components are loaded but the style is not
If I set the defineCustomElements in page layout the component appears and disappears soon after, but in html it stays but its style doesn’t!
@gabrielleacuba & @TheNinza - not really to do with SSR, but your problems are due to an issue with Nextjs (not Stencil) in that it removes any 3rd party tag injected into the head (e.g. analytics etc) vercel/next.js#11012
Activity
johnjenkins commentedon May 17, 2023
👋 took the liberty of forking the repro - https://github.com/johnjenkins/nextjs13-ssr-hydration - applied #2938.
Seems to be fixed. I'd love to get that PR merged one day.
Appreciate it would be quite the undertaking at this stage but I'm still around and willing to make it happen :)
mayerraphael commentedon May 24, 2023
We have full SSR and Stencil/NextJS running by using JohnJenkins 2.23 build with the integrated PR (for most of the slot problems) and we hydrate Stencil before NextJS, by putting
defineCustomElementsin abeforeInteractiveScript or a plain old <script> with dangerouslySetInnerHTML in the_documentpage.This requires you to provide the component library via an asset in the server.js. (see https://github.com/mayerraphael/stencil-ssr-bug/blob/main/my-app/server.js#LL23C1-L23C91)
Also be sure to set
<body style={{ display: "block" }}>as NextJS has the body hidden until NextJS is initialized in dev mode, causing problems if components usecomponentDidLoadand calculate some height/width there.Here is a link to a recent repo of mine: https://github.com/mayerraphael/stencil-ssr-bug/blob/main/my-app/pages/_document.tsx (it is missing the body fix, as this caused the problems we wanted to show with this repo)
https://nextjs.org/docs/pages/building-your-application/optimizing/scripts#strategy
The PR @johnjenkins named is so vital for us. SSR is so buggy ATM without this PR that it is just straight unusable.
gabrielleacuba commentedon May 24, 2023
Can any of you help me? I have my company’s design system that is using the stencil and they work perfectly in the next version that uses the pages/ folder, but trying to use it in the app/ folder in the new 13.4 version the components are loaded but the style is not
If I set the
defineCustomElementsin page layout the component appears and disappears soon after, but in html it stays but its style doesn’t!TheNinza commentedon Jun 6, 2023
I am facing the same issue @gabrielleacuba . Any updates on this since you posted it?
johnjenkins commentedon Jun 8, 2023
@gabrielleacuba & @TheNinza - not really to do with SSR, but your problems are due to an issue with Nextjs (not Stencil) in that it removes any 3rd party tag injected into the head (e.g. analytics etc) vercel/next.js#11012
It was fixed in April via an experimental flag: vercel/next.js#47938. Just add:
To you next.config
johnjenkins commentedon Jun 8, 2023
@mayerraphael in case you weren't aware - the PR has been picked up in a dev version of Stencil (3.3.0-dev.1685496483.a311f36).
Full coverage - https://discord.com/channels/520266681499779082/1108109881870925875/1108109881870925875
christian-bromann commentedon Jun 14, 2024
closing in favor of #5831