-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Use devalue for island props serialization #12093
Conversation
🦋 Changeset detectedLatest commit: 1759606 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is blocked because it contains a minor
changeset. A reviewer will merge this at the next release if approved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks for reviving my efforts! 🎉
For context, seroval
is used by Solid and has more comprehensive support for common cross-environment primitives. The other benefit is that we wouldn't need to generate the (0, eval)()
step, because seroval
outputs self-contained JS strings.
Of course, devalue
is also a great choice—I'll leave the final call up to you.
I did some checks and I think they're largely the same.
I think both devalue and seroval outputs similar JS that still requires us to eval. We're putting the values in attribute values, so we have to manually eval it again. devalue also seem to be much smaller, which reduces the ssr bundle size. Comparison: devalue (5.21 kB -> 2.16 kB (gzip)) and seroval (28.2 kB -> 7.75 kB (gzip)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. Makes a lot of sense that this matches the supported types for content layer too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should introduce eval. Currently users are required to use unsafe-inline
if they are using a CSP policy, this change would require that they also use unsafe-eval
. Given the number of people who are not satisfied with an unsafe- at all, we should be moving in the direction of not requiring it, and I don't see how we can make CSP work with eval in the code.
This could use |
@ascorbic how much client JS are we adding by bringing Also consider here that the only thing we gain by bringing in a dependency is not needing to maintain our custom serializer/deserializer. But we haven't had much maintenance on the one we have. This @natemoo-re did a spike a while back (last year IIRC) on going back to inlining the hydration script rather than using astro-island. If we did that we could use these sorts of tools again because there would be no client-side penalty for deserialization. I think that's probably what we should do instead of this. And for now, just add Infinity as a new type in our custom serializer. |
@matthewp supporting As Astro pushes into more ecomm/interactive usecases, the potential payoff on serialization optimizations will continue to grow. Could pair nicely with any cross-island communication explorations, if that's ever on the table. |
We can't do that because that will require
devalue Looks like there's no other way to implement this without size tradeoffs. I do still think the edgecases being handled by devalue is valuable but maybe in the future. |
Changes
fixes #12088
partially revives #8004
compared to #8004, this uses
devalue
instead ofseroval
as I don't really understand the main difference withseroval
, and we're already usingdevalue
in our codebase. It also doesn't completely serialize other island information, only the props, to minimize the change surface area.Testing
added test for #12088 and removed some irrelevant ones
Using the repro in #7978, this reduces the serialized prop value size ("Astro bytes"):
It could get even lower by serializing string values with single quotes to prevent needing escaping, but I think for now it's fine as a stop gap.
Docs
It doesn't look like we document specific serialization edge cases other than https://docs.astro.build/en/guides/framework-components/#passing-props-to-framework-components, which is still true today (regarding function serialization)