Skip to content
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: custom serialization #7223

Draft
wants to merge 4 commits into
base: build/v2
Choose a base branch
from
Draft

feat: custom serialization #7223

wants to merge 4 commits into from

Conversation

wmertens
Copy link
Member

@wmertens wmertens commented Jan 2, 2025

This PR adds symbols to mark objects as (no/yes)serializable via symbols instead of via a Set, adds a symbol prop that will get called on serialization for custom serialization, and provides a new Signal type that lazily manages a non-serializable value.

Note that this is basically the same as useComputed$, except that it is invalidated during SSR so that when the value gets read on the client it will always run the compute function.

Also note that useComputed$ now passes the previous value to the compute function, to keep the implementation compact. This seems like it might be useful, should we document this?

Everything works, looking for comments on implementation, naming etc.

Copy link

changeset-bot bot commented Jan 2, 2025

🦋 Changeset detected

Latest commit: 9009520

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@qwik.dev/core Major
eslint-plugin-qwik Major
@qwik.dev/react Major
@qwik.dev/router Major
create-qwik Major

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

@Varixo
Copy link
Member

Varixo commented Jan 2, 2025

Looks great, but what about deserialization those objects?

@wmertens
Copy link
Member Author

wmertens commented Jan 2, 2025

Looks great, but what about deserialization those objects?

That's what the createSerialized$ does

@thejackshelton
Copy link
Member

Does this mean we might be able to serialize functions from other libraries, like vanilla js?

FEAT: `NoSerializeSymbol`: objects that have this defined will not be serialized

FEAT: `SerializerSymbol`: objects that have this defined as a function will get it called with the object as a parameter during serialization. The function should return the data that should be serialized.
Use this to remove cached data, consolidate things etc.
@wmertens
Copy link
Member Author

wmertens commented Jan 3, 2025

@Varixo @thejackshelton gaah I had forgotten to push the actual commit 😅

@wmertens
Copy link
Member Author

wmertens commented Jan 3, 2025

Does this mean we might be able to serialize functions from other libraries, like vanilla js?

Yes exactly. You need to add a symbol prop that serializes the value and then provide a deserializer that will get called lazily.

Copy link

pkg-pr-new bot commented Jan 3, 2025

Open in Stackblitz

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/core@7223
npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/router@7223
npm i https://pkg.pr.new/QwikDev/qwik/eslint-plugin-qwik@7223
npm i https://pkg.pr.new/QwikDev/qwik/create-qwik@7223

commit: 103e3c1

Copy link
Contributor

github-actions bot commented Jan 3, 2025

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
qwik-docs ✅ Ready (View Log) Visit Preview 103e3c1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants