feat: more advanced prop serializer for islands (#1224)
This commit adds support for an advanced (de)serializer that is used for page state (island props and plugin state). This new serializer supports maintaining references (thus supporting circular objects, and multi-referenced objects). This is a pre-requisite for allowing to pass signals, JSX, Uint8Arrays, Date, and many other "advanced" values.
This commit is contained in:
@@ -31,19 +31,21 @@ export default function MyIsland() {
|
||||
An island can be used in a page like a regular Preact component. Fresh will take
|
||||
care of automatically re-hydrating the island on the client.
|
||||
|
||||
Passing props to islands is supported, but only if the props are JSON
|
||||
serializable. This means that you can only pass:
|
||||
Passing props to islands is supported, but only if the props are serializable.
|
||||
Fresh can serialize the following types of values:
|
||||
|
||||
- Primitive types `string`, `boolean`, and `null`
|
||||
- Most `number`s (`Infinity`, `-Infinity`, and `NaN` are silently converted to
|
||||
`null`, and `bigint`s are not supported)
|
||||
- Plain objects with string keys and primitive, plain object, or array values
|
||||
- Arrays containing primitives, plain objects, or other arrays
|
||||
- Plain objects with string keys and serializable values
|
||||
- Arrays containing serializable values
|
||||
|
||||
It is currently not possible to pass complex objects like `Date`, custom
|
||||
classes, or functions. This means that it is not possible to pass `children` to
|
||||
an island, as `children` are VNodes, which are not serializable. To find out
|
||||
more about JSON serializable values, check out
|
||||
[how `JSON.stringify()` works](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description).
|
||||
Circular references are supported. If an object or signal is referenced multiple
|
||||
times, it is only serialized once and the references are restored upon
|
||||
deserialization.
|
||||
|
||||
Passing complex objects like `Date`, custom classes, or functions is not
|
||||
supported. This means that it is not possible to pass `children` to an island,
|
||||
as `children` are VNodes, which are not serializable.
|
||||
|
||||
It is also not supported to nest islands within other islands.
|
||||
|
||||
Reference in New Issue
Block a user