Skip to content

[css-view-transitions] Making the callback param non-nullable #9460

Closed

Description

@vmpstr

In css-view-transitions, we define the following, an optional nullable callback with the default value of null:

partial interface Document {
  ViewTransition startViewTransition(optional UpdateCallback? updateCallback = null);
};

In #8960 we resolved to change the callback (in Level 2) to take either a callback or a dictionary of options. Naively, this would have been the following

ViewTransition startViewtransition(optional (UpdateCallback or Dictionary)? param = null)

But that's not possible because of the following restriction:

A nullable type is an IDL type constructed from an existing type (called the inner type) [...] The inner type must not be:

A simple solution is to just make these non-nullable:

ViewTransition startViewtransition(optional (UpdateCallback or Dictionary) param)

Additionally, for consistency, it would be nice to make the existing view transition callback non nullable as well, while still remaining optional:

ViewTransition startViewtransition(optional UpdateCallback updateCallback)

I believe the only script visible change here is that this would preclude startViewTransition(null) from being valid. I could be wrong though. If I'm right, then I think that's fine, since that doesn't seem like a correct use of this API.

Activity

  1. css-meeting-bot commented on Oct 18, 2023

    @css-meeting-bot
    Member

    The CSS Working Group just discussed [css-view-transitions] Making the callback param non-nullable, and agreed to the following:

    • RESOLVED: Make the parameter non-nullable, but keep it optional
    The full IRC log of that discussion <emilio> noamr: we have a startViewTransition call that takes one param that is marked as optional nullable with default of null
    <emilio> ... we resolved to extend this to allow a dictionary
    <emilio> ... so naively it'd be an optional nullable union
    <emilio> ... but that's not possible in WebIDL
    <noamr> it's vmpstr, not noamr
    <emilio> vmpstr: so proposal is making it non-nullable
    <emilio> ... this only precludes null of being a valid parameter
    <emilio> ... it'd still be optional
    <emilio> astearns: if we decide on null as a naive way of dealing with the optionality?
    <emilio> ... was there a purpose?
    <emilio> vmpstr: there wasn't, it was just in the editor's draft since the beginning
    <khush> +1
    <emilio> q+
    <khush> q+
    <astearns> emilio: so if null is passed we will start throwing?
    <astearns> ack emilio
    <emilio> vmpstr: that's right
    <emilio> emilio: hopefully nobody is doing that, if you're fine with the compat risk seems fine
    <emilio> vmpstr: usage is low enough
    <emilio> emilio: sounds good then
    <emilio> khush: to add to vmpstr there's no production usecase where you'd do that
    <emilio> ... because the callback is where you are supposed to mutate the DOM
    <emilio> vmpstr: to clarify it's still optional, it'd be just explicit null that could be problematic
    <emilio> RESOLVED: Make the parameter non-nullable, but keep it optional
  2. added a commit that references this issue on Oct 18, 2023
    c1b9c88
  3. added a commit that references this issue on Oct 18, 2023
    fae0709
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions