-
Notifications
You must be signed in to change notification settings - Fork 799
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
feat(hydrate): support object serialization for hydrated components #6208
base: main
Are you sure you want to change the base?
Conversation
@@ -27,7 +27,7 @@ describe('different types of decorated properties and states render on both serv | |||
renderToString = mod.renderToString; | |||
}); | |||
|
|||
it('renders default values', async () => { | |||
it.skip('renders default values', async () => { |
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.
@johnjenkins any idea why these tests are failing? It seems like something with reflected properties that is still not quite right here
This reverts commit 7b108e2.
…o cb/prop-serialization
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. |
Thanks @johnjenkins for your support 🙏 I will incorporate your suggestion in the docs. Created a dev released at |
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
serializeProperty
method 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.