Skip to content

[cssom-view-1] Scroll methods in Element and Window return Promises #12355

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mustaqahmed
Copy link
Member

Switch the return type for the scroll methods from undefined to Promise<undefined> as per the discussion and resolution in #1562 (comment).

Fixed: #1562.

Switch the return type for the scroll methods from `undefined` to `Promise<undefined>` as per the discussion and resolution in w3c#1562 (comment).

Fixed: w3c#1562.
@mustaqahmed mustaqahmed requested review from emilio and vmpstr June 17, 2025 14:58
@flackr
Copy link
Contributor

flackr commented Jun 23, 2025

In the discussion we talked about the argument to the promise being an object which would tell the developer the result of the scroll, e.g. to know if it was cancelled / interrupted as was brought up a few times as a common thing to need to know.

@mustaqahmed
Copy link
Member Author

In the discussion we talked about the argument to the promise being an object which would tell the developer the result of the scroll, e.g. to know if it was cancelled / interrupted as was brought up a few times as a common thing to need to know.

That's correct. The problem is that it not yet defined how the promise would be resolved to mark scroll completion vs interruption. I can update this PR to resolve with a true to mark completion and false "otherwise" but I am hesitant because of a few reasons:

  1. It is perhaps not okay to add normative things w/o discussion, right? E.g. we don't know if we should use a Boolean here vs an enum.

  2. What does that "otherwise" mean to be precise? Does one programmatic scroll request interrupt all pending promises? Or only the pending ones for the same scroller?

  3. We may need additional text in the current scroll algorithms to "collect" pending scrolling requests. To me a follow-up PR after this one seems cleaner.

I am proposing to land this PR as "closing" #1562, staring a new spec issue to discuss 1+2 above, and then hash out 3 in the PR for that new issue.

@flackr
Copy link
Contributor

flackr commented Jul 10, 2025

In the discussion we talked about the argument to the promise being an object which would tell the developer the result of the scroll, e.g. to know if it was cancelled / interrupted as was brought up a few times as a common thing to need to know.

That's correct. The problem is that it not yet defined how the promise would be resolved to mark scroll completion vs interruption. I can update this PR to resolve with a true to mark completion and false "otherwise"

I would suggest that it not resolve with a boolean but rather with an object, e.g. define a ScrollResult, that we can add to if we later discover that we want to pass additional information. That said, having a boolean there and opening an issue for whether we should change it is a good thing.

but I am hesitant because of a few reasons:

  1. It is perhaps not okay to add normative things w/o discussion, right? E.g. we don't know if we should use a Boolean here vs an enum.

This is normal, the resolution we have is effectively to pursue specifying and prototyping the feature. It's fully expected that in the process of doing this the implementor may make some opinionated decisions in writing the spec and bring those decisions back to the working group. Having something implemented will make it easier to have examples where we can show how the value would be used.

  1. What does that "otherwise" mean to be precise? Does one programmatic scroll request interrupt all pending promises? Or only the pending ones for the same scroller?

It would be valuable to define this to mean what we think makes the most sense. IMO this is anything that prevents completing the original scroll request. A programmatic scroll request on an unrelated scroller probably should not interrupt it. A scroll on the same scroller would mean that we are no longer actively scrolling to the originally requested location.

  1. We may need additional text in the current scroll algorithms to "collect" pending scrolling requests. To me a follow-up PR after this one seems cleaner.

I am proposing to land this PR as "closing" #1562, staring a new spec issue to discuss 1+2 above, and then hash out 3 in the PR for that new issue.

It is better to have the boolean there and to add an inline issue in the spec that says we need to agree on the type and when it is successful / unsuccessful. This shows spec readers that the API is likely to change, demonstrates the use case and can even point to the issue for people to add their feedback. Here's an example from css-images-5:

ISSUE: Make sure behavior is <a href="https://github.com/w3c/csswg-drafts/issues/7058#issuecomment-1057553833">properly consistent for SVG</a>.

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.

[cssom-view] Consider making scroll methods return promises
2 participants