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

Support HTML serialization/structured clone #548

Closed
littledan opened this issue May 8, 2020 · 16 comments
Closed

Support HTML serialization/structured clone #548

littledan opened this issue May 8, 2020 · 16 comments
Assignees
Milestone

Comments

@littledan
Copy link
Member

@slightlyoff pointed out that Temporal objects should transparently be serialized by HTML, i.e., structured clone, i.e., "just working" round trip in postMessage (including in Node.js worker_threads!), IndexedDB, etc. Supporting this would be a matter of making a PR against HTML analogous to whatwg/html#3480 . I don't think custom calendars or timezones could be serializable (causing a DataCloneError), but the built-in ones should be fine to serialize. No rush to take an action to take right now; we can prepare this PR when this proposal is at (or almost at) Stage 3.

@kaizhu256
Copy link
Contributor

didn't indexeddb refuse to support bigint? temporals would be even a harder sell.

@littledan
Copy link
Member Author

@kaizhu256 IndexedDB supports BigInt as values. As keys, there wasn't sufficient demonstrated interest in use cases. I expect us to follow this pattern for Temporal as well: initially, support Temporal as values (through structured clone), and later possibly as keys (through special IndexedDB-specific support) if there is sufficient interest.

@littledan
Copy link
Member Author

For background: w3c/IndexedDB#231

@kaizhu256
Copy link
Contributor

k thx for clarification

@littledan littledan added this to the Stage 4 milestone May 14, 2020
@ryzokuken ryzokuken modified the milestones: Stage 4, Stage 3 May 20, 2020
@littledan
Copy link
Member Author

Stage 3 is probably best for this so that implementers are well aware that structured clone is supported when they go about implementing Temporal. This is a straightforward task.

@Ms2ger
Copy link
Collaborator

Ms2ger commented Nov 17, 2020

  • How do we deal with datetimeish objects with a custom timezone or calendar?
    • Throw?
    • Serialize the string id and call X.from on the other side?
  • How do we distinguish custom timezone or calendar objects anyway? When using subclassing, they have all the state we'd usually use to distinguish built-ins

@littledan
Copy link
Member Author

For custom tz and calendar: I suggest that we go by internal slots. If they lack the internal slot of the built-in calendar or tz, throw. If they do have the internal slot but also are a subclass with some methods overridden, ignore those changes and just serialize by the id.

@ljharb
Copy link
Member

ljharb commented Nov 17, 2020

I agree with that ^ but it speaks to the need for subclasses to be able to provide an arbitrary ID, not just a built-in one, otherwise on the other side, subclasses will be of the wrong type.

@littledan
Copy link
Member Author

I don't see how providing an arbitrary ID would make it work... you would still need matching behavior on the other side somehow.

@ljharb
Copy link
Member

ljharb commented Nov 17, 2020

That's true - so subclasses just aren't effectively serializable?

@littledan
Copy link
Member Author

Right. In general, functions and classes are not serializable.

@ljharb
Copy link
Member

ljharb commented Nov 17, 2020

Would it be better then for serializing subclasses to throw rather than silently serializing incorrectly?

@littledan
Copy link
Member Author

I'm not really sure of how the details should work out. HTML has some cases where things throw and some where serialization changes a bit. I think we should look at the details and generally follow HTML conventions where possible. If we have a choice point, I agree with preferring throwing, but I consider this lower priority than following conventions.

@ptomato
Copy link
Collaborator

ptomato commented Jan 13, 2021

HTML pull request: whatwg/html#6284

@littledan
Copy link
Member Author

littledan commented Jan 26, 2021

@Ms2ger has completed a first draft of structured clone for Temporal types at whatwg/html#6284 . I think this is enough for Stage 3, but we should have multiple browser support by Stage 4.

@ptomato
Copy link
Collaborator

ptomato commented Dec 8, 2022

Closing this, in favour of whatwg/html#6284.

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

No branches or pull requests

6 participants