Skip to content

[css-typed-om] structuredClone for typed-om objects #1101

Open

Description

@DevSDK

"structuredClone can’t deal with CSSUnitValue objects" issue is filed on crbug [1].

Currently, the css-typed-om spec[2] does not mark the [Serializable] attribute for typed-om objects.
Consequently, these objects are not contained in the platform objects that can be serializable according to the HTML spec [3].

So the browsers comply with that spec that throws an exception.
However, the following codes look very natural:

Given this, browsers appropriately throw an exception to comply with the spec.
However, consider the following code:

structuredClone(CSS.px(2))

This looks quite intuitive and straightforward.

If there is no extra context that I missed, could we consider supporting it?

[1] https://bugs.chromium.org/p/chromium/issues/detail?id=1444708&q=is%3Astarred&can=2
[2] https://www.w3.org/TR/css-typed-om-1/#cssunitvalue
[3] https://html.spec.whatwg.org/multipage/structured-data.html#serializable-objects

Activity

  1. DevSDK commented on Sep 14, 2025

    @DevSDK
    ContributorAuthor

    @tabatkins Hi Tab, gentle ping for this issue and PR :). If there are particular no problem, I'll opened the CL for that!

  2. tabatkins commented on Sep 15, 2025

    @tabatkins
    Member

    Whoa, sorry for missing this!

    It does seem straightforward to make them Serializable. Do we do this commonly? I'm just not sure what the web platform's usual mode of operation is for marking things as cloneable.

  3. DevSDK commented on Sep 15, 2025

    @DevSDK
    ContributorAuthor

    Yeah, it is straightforward!

    AFAIK, the Serializable objects are marked as [Serializable] in idl due to structuredClone spec in whatwg:

    https://html.spec.whatwg.org/multipage/structured-data.html#serializable-objects

    Platform objects can be serializable objects if their primary interface is decorated with the [Serializable] IDL extended attribute. Such interfaces must also define the following algorithms:

    and in the StructuredSerializeInternal ( value, forStorage [ , memory ] ), part of internal operation for structuredClone

    1. Otherwise, if value is a platform object that is a serializable object:
      ...
    2. Otherwise, if value is a platform object, then throw a "DataCloneError" DOMException.

    So I think clonable by structuredClone equals to Serializable...?

    E.g.,

    For DOMMatrix (that supports structuredClone):

    [Exposed=(Window,Worker),
     Serializable]
    interface DOMMatrixReadOnly {
    ...
    }
    [Exposed=(Window,Worker),
     Serializable,
     LegacyWindowAlias=(SVGMatrix,WebKitCSSMatrix)]
    interface DOMMatrix : DOMMatrixReadOnly {
    ...
    }
  4. DevSDK commented on Sep 21, 2025

    @DevSDK
    ContributorAuthor

    One unclear thing was CSSImageValue, as per spec:

    Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)]
    interface CSSImageValue : CSSStyleValue {
    };

    it seems probably not Serializable... yet...

  5. DevSDK commented on Sep 28, 2025

    @DevSDK
    ContributorAuthor
  6. DevSDK commented on Sep 30, 2025

    @DevSDK
    ContributorAuthor

    cc. @bramus :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions