feat(hydrate): support object serialization for hydrated components#6208
Merged
christian-bromann merged 33 commits intomainfrom Apr 3, 2025
Merged
feat(hydrate): support object serialization for hydrated components#6208christian-bromann merged 33 commits intomainfrom
christian-bromann merged 33 commits intomainfrom
Conversation
johnjenkins
reviewed
Mar 18, 2025
| }); | ||
|
|
||
| it('renders default values', async () => { | ||
| it.skip('renders default values', async () => { |
Member
Author
There was a problem hiding this comment.
@johnjenkins any idea why these tests are failing? It seems like something with reflected properties that is still not quite right here
johnjenkins
reviewed
Mar 19, 2025
This reverts commit 7b108e2.
…o cb/prop-serialization
Contributor
|
A side note (perhaps tangentially related or not at all ... or just a note for documentation) A similar result can be achieved within Stencil right now using await renderToString(response.body, {
beforeHydrate: (doc: Document) => {
doc.querySelector(`my-component`).someComplexThing = new Map(...)
},
})It may save on payload bytes if the object in question is already being handled / serialised by the framework in question. |
Member
Author
|
Thanks @johnjenkins for your support 🙏 I will incorporate your suggestion in the docs. Created a dev released at |
8 tasks
3 tasks
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What is the current behavior?
Stencil has only limited support for the serialization of objects in cases where you want to server side render a component. Support was given for basic objects, e.g.
But not for more complex ones like Map, Set, Infinity or symbols.
What is the new behavior?
The hydrate module now exports a
serializePropertymethod that can help to properly serialize a property of any type, e.g. given the following component:You could serialize it via:
Which will output:
Documentation
wip.
Does this introduce a breaking change?
Testing
Added an e2e WebdriverIO test to verify if a component with complex types can be rendered and hydrated.
Other information
The implemented serialization and deserialization primitives come from the WebDriver Bidi protocol defined in
7.5.3.7. The script.LocalValue Type(https://www.w3.org/TR/webdriver-bidi/#type-script-LocalValue) where this is used to serialize complex values between a local script and a remote browser. I made an addition to parse the serialized object into a base64 string and prefixed it withserialized:to clearly identify a serialized value.