fix: serialize thenables in hydratable
#17275
Closed
+13
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This serializes thenables in
hydratable. However, there is a slight discrepancy: if you have an object that is a thenable on the server, it will be converted to aPromiseon the client. I'm not sure if we should:Promises (and maybe reflect that in the types?)thenfunction), with athenfunction that resolves to the awaited value, which would look like:Option 3 would probably be the best in terms of correctness, but it'd also be the most complex; we'd have to add some extra errors and checks for values that cannot be serialized (since there isn't a way to omit a property from a non-POJO while preserving its prototype, which would let us make
devaluedo the checking for us), which would raise the issue of having two types of serialization errors: those fromdevalueand those fromsvelte, which would make error handling trickier. Additionally, we'd likely have to preserve key order in thenables, which could get ugly.Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.packages/svelte/src, add a changeset (npx changeset).Tests and linting
pnpm testand lint the project withpnpm lint