Skip to content

Allowing synchronous reads of then accessors on non-built-in objects #4

@Rich-Harris

Description

@Rich-Harris

Hello — I found my way here via a conversation on Bluesky and hope this is the right venue in which to raise this.

From what I gather, there's an appetite to change the behaviour of thenables in a way that could impact certain (subjectively!) valid use cases. I'll articulate ours as succinctly as I can. I'm a maintainer of Svelte, which is a component framework that uses signal-based reactivity. Recently, we added the ability to await values directly inside components in a way that is coordinated by the framework:

<p>{await myQuery()}</p>

The awaited values are often thenables representing data from a server. {await myQuery()} updates when that data updates. For this to work, Svelte must know that the {await myQuery()} effect depends on the state, internal to the returned query thenable, that is updated when the data changes. By making then a getter on the object, we can read the state during the effect's execution, which builds the dependency graph that allows the framework to keep the UI in sync with the data.

You can see that in action here, or in the YouTube clip at the top of the linked Bluesky conversation.

I'll confess I don't have a firm grasp of the concerns that this proposal is addressing, or even whether use cases such as ours would be prevented by the mitigations under discussion. But I thought it worth sharing an example of the sort of thing that could break if the behaviour of await thenable were to change, in case it's relevant to future discussions. In our case we could mitigate it with more invasive code transformations (i.e. we transform await myQuery() to await readThen(myQuery()), just in case the awaited expression is the kind of thenable I described above) but this obviously has its own costs.

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