solid-start: [Bug?]: SSR / Hydration Mismatch for Ark UI + Panda CSS Project (Stackblitz example included)
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior šÆ
There is a working example of solid-start + Ark UI + Panda CSS provided in the Park UI lib here:
https://github.com/cschroeter/park-ui/tree/main/examples/panda/solid/solid-start
This project loads without issue both in stackblitz and also when I run the project locally.
When I make some minor modifications to include the ark ui datepicker component (with Panda CSS recipes) in this demo stackblitz, the project loads without issue.
Here is a live demo in Stackblitz: https://stackblitz.com/edit/github-ivec47?file=src%2Froutes%2Findex.tsx%3AL11,src%2Fcomponents%2Fui%2Fdate-picker.ts
Here is the forked source where Iāve introduced the change in my github fork https://github.com/brianfeister/park-ui/tree/solid-example-wip/examples/panda/solid/solid-start
The Stackblitz above works! (š ) ⦠but when I run the same code locally, I get the following error:
Stepping through this in Chrome Debugger, I see the getNextElement() function (in the erroring component) yielding a getHydrationKey() of 0-0-0-0-0-0-0-0-0-1-0-0-0-0-0-1-0-0-2-0-0-1-0-0-0-0-2-0-2 but searching the DOM in the elements tab yields no matching key in the DOM which seems suspect
Expected behavior š¤
Cloning the repo https://github.com/brianfeister/park-ui/tree/solid-example-wip/examples/panda/solid/solid-start and running npm i && npm run dev from this directory should execute successfully
Steps to reproduce š¹
Steps:
git clone git@github.com:brianfeister/park-ui.git && git checkout solid-example-wipcd park-ui/examples/panda/solid/solid-start && npm i && npm run dev- Open
localhost:3000 - Hydration error ā ļø
Context š¦
No response
Your environment š
System:
Mac OS Sonoma 14.1.2
Dep Versions:
https://github.com/brianfeister/park-ui/blob/solid-example-wip/examples/panda/solid/solid-start/package.json
About this issue
- Original URL
- State: open
- Created 6 months ago
- Comments: 31 (14 by maintainers)
I think I finally cought it. This error had been hapenning here and there very inconsistently but I finally got to a case where I can reproduce the error 100% of the times. I think it has to do with how the SSR handles components inside of a route.
I created two routes. Both display a table using TankStank table The first one, I put the table directly into the function of the route, like so (simplified example):
It worked perfecly, no matter how many times I reload or change routes. It works as expected ā
Then I took the exact same code, and I put the table inside a component like so:
Then it works the first time, but as soon as I hard refresh (Shif + Ctrl + R in Chrome) It breaks ā. 100% of the time. So its not about the library (In this case TankStank) because I used the same logic, same component and same everything. The issue happened as soon as I encapsulated the logic inside the route in a compontent. And it works fine when you enter the module for the first time, so the code works; if you navigate between routes it works well also. But as soon as you hard reload, it breaks (sometimes just with normal refresh as well).
So I append the step by step on how to reproduce the issue. I tested it myself with a brand new clone and it reproduced 100% of the times
git clone https://github.com/danicruz0415/solidStartErrorExample.gitcd .\solidStartErrorExample\, runnpm installthen runnpm run devhttp://localhost:3000/app/teachers/In the menu on the left you will see two options: āTeachers with bugā and āTeachers without bugā. If you navigate between them using the menu, you will see that the error does not happen. If you go to āTeachers without bugā, you will see that no matter how many times you refresh, the error does not occur. But if you go to āTeachers with bugā and refresh, it immediately breaks. Both pages are identical in content and logic, the only difference is that one returns the table directly (this one works) and the other one encapsulates the table inside a component (this one breaks)
I tried to eliminate as much code without losing the error, to have a shorter version. I hope this helps findind the cause and I hope with this example you can finally replicate the issue, as all previews examples sometimes failed and sometimes worked fine.
PS: I dont upload it to stackblitz, because all the examples posted by other people, when I run them it only shows āUpgrade Requiredā. I donāt know why. I read online that I only had to wait a bit, but It stays the same way for as much time Iāve left it that way.
Thank you so much for taking the time to look into this. I am tuned for any extra information that I may be able to recover. For now this is the information of my runtime:
Think what this does. On the server it shows
serverand when the client gets there it now doesnāt. Which means that there is a hydration mismatch. It being undefined happens to be the way we handle defering the diff for stuff like lazy components, so it is getting past detection.But before we get into how it fails we have to look at why. For things to hydrate the client needs to be in the same initial state as the server. So
isServercould never be used as a conditional in JSX. It could be used to say swap a data source or run code that only happens on server or client but it could never make a structure change to the DOM. If you want to show something extra in the client then you need to apply that change afterwards in anonMount. Wanting something to only render on the server isnāt as easy but also doesnāt make a ton of sense (since itād be immediately hidden).Also @danicruz0415 thanks for the updated reproduction. I will take a look. Itās quite possible these are different issues but any hydration issue is good to find.
@danicruz0415 , excellent, I can confirm this reproduces the error as described, and my environment is quite different:
macos 4.2.1 arm64 / pnpm / firefox 119
Hi I hit the same issue in a brand new project using v0.4.9. I reduced the code as much as possible trying to keep a reproducible version of the error and got to reproduce it with a simple div and a h1: https://github.com/danicruz0415/solidStartErrorExample
Its really strange, because I created two routes:
/about/and/auth/, both look almost identical to me (the component is just a div and a title) but for some reason the first one works and the second one throws an error.I restarted many times and ran
npm run devagain but the same thing happens. I read about the issue and it says that it may be caused by components that have non-deterministic behavior, but I dont think thatās the case because here its just a divI attach screenshots of both, almost identical components, one of which fails, and the other one that works fine
Failing component
Component that works properly
As you can see, on the element that fails, on the browser inspector can be seen that the element has a
data-hk="0-0-0-0-0-0-0-0-1-0-0-0-0-0-0-0-0-0-0-0"but the error says that the hidration system is looking for the key0-0-0-0-0-0-0-0-1-0-0-0-0-0-0-0-0-0-1(last digit is different)On the other hand on the element that works, the data-hk is the same, but it works fine. Both elements are under the same path so they donāt have different layouts or anything. This is all the information I could gather on the issue. I hope it helps to find what the issue is.
Hello,
Iām having issues with Hydration Mismatch in my test project. Navigating to home page works OK, but if I reload page I get Hydration Mismatch error:
This is StackBlitz demo. Basically I use SuspenseList with 3 internal Suspense.
Hi,
Iām having similar issues with Hydration Mismatch too in a very basic project. Hereās the repo: https://github.com/alveshelio/solidstart-authjs-bun Iām using bun v1.0.22 and all my dependencies in the project are up to date. Iāve created a new page āContactā and whenever I try to visit it, the first time I get a Not Found and if I do a refresh on the page I get the Hydration Mismatch error
This only happens when using
bun, if I usepnpmthen I donāt get the Not Found nor the Hydration Mismatch error.Well⦠Iām still stripping stuff away. Trying to use just
ArkDatePicker.Rootdirectly and still hitting issues. Which means now I want to look at how thatās implemented. A lot of Solid libraries I realized recently arenāt built properly for SSR. There could be Solid bugs in there as well. But Iām pretty sure it Ark-UI here. I see hydration IDs in the DOM around 6 and 10 where we are looking for 2. This suggests a bunch of siblings created prematurely.Yeah I think so. Issue is in the DatePickerDemo specifically. Probably related to prematurely rendering props that arenāt inserted into the DOM. Itās a lot to debug⦠so starting by deleting until it works. But I think the issue is probably fairly high up.
EDIT: Yeah
DatePicker.Rootwith nothing else has a problem which makes me think the problem is in the HoC wrappers.