-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Map and Set entries reversed on page hydration #13093
base: dev
Are you sure you want to change the base?
Conversation
When the loader data contains a `Map` or `Set` object, the data maintains the correct order in the server-rendered response. However, once the page hydrates, the order of the items in the `Map` or `Set` are reversed, leading to a hydration error from React.
This is me signing the Contributor License Agreement (CLA).
|
So we are less likely to accidentally match text content that appears elsewhere in the page markup.
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
I tried looking into this and here is what I found: The [{"_1":2,"_9":-5,"_10":-5},"loaderData",{"_3":4,"_8":-5},"routes/map",["M",5,5,6,6,7,7],1,2,3,"root","actionData","errors"] (The After the call to turbo-stream's So this could be an issue with the version of turbo-stream being used. I did not look into that any further, though. |
It looks like this is caused by the version of turbo-stream currently in use. I tried encoding and decoding a I see that there's a pull request to upgrade turbo-stream to v3.10. I'll keep this pull request open for the tests at least. Since the turbo-stream upgrade is going to be a major change (the turbo-stream format is different in v3 versus v2), some people may not be able to upgrade right away. I don't know if the maintainer(s) of turbo-stream would be open to releasing another v2 version that would fix this issue. I opened a turbo-stream issue asking about that possibility. If not, maybe maintaining a v2 fork would be helpful. |
When the loader data contains a
Map
orSet
object, the data maintains the correct order in the server-rendered response. However, once the page hydrates, the order of the items in theMap
orSet
are reversed, leading to a hydration error from React. This also breaks the specifications forMap
andSet
, since they specify that the iteration order of the entries should match the insertion order.This is a failing bug report test, demonstrating this behavior.