Skip to content

ScrollBehavior definition is missing 'instant' for window.scrollTo #47441

Closed

Description

Bug Report

?? Search Terms

instant
ScrollBehavior
window
scrollTo
type definition

?? Version & Regression Information

v4.5.4, but it's also mentioned in #46654 (v4.4.4) and #28755 (v3.2.1)

? Playground Link

Playground link with relevant code

?? Code

window.scrollTo({
  top: 0,
  left: 0,
  behavior: 'instant' // This should be allowed
})

?? Actual behavior

The value of instant cannot be assigned to behavior when using window.scrollTo.

?? Expected behavior

The value of instant is allowed when using window.scrollTo according to https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo as well as in real-world testing in major browsers. I just tested window.scrollTo with instant on Chrome, Firefox, and macOS Safari and it does not give the same behavior as auto. In my tests, auto produced smooth scrolling and instant scrolled instantly.

Please note that the MDN documentation specifies different behavior options for element.scrollTo and element.scrollIntoView vs. window.scrollTo. This bug report is specific to window.scrollTo. The existing ScrollBehavior type definition will most likely need to be bifurcated to handle all functions correctly.

Until the type definition is fixed, you can get the instant scrolling behavior by casting as any:

window.scrollTo({ top: 0, left: 0, behavior: 'instant' } as any)

Activity

  1. RandScullard commented on Jan 14, 2022

    @RandScullard
    Author

    Please note that this issue is very similar to #46654, but that issue was related to element.scrollTo and this issue is related to window.scrollTo. The two functions have different options for ScrollBehavior. (And thanks to Craig Patik (@patik) - his work on #46654 saved me time in creating this issue!)

  2. BayanBennett commented on Apr 27, 2022

    @BayanBennett

    Note that behavior: "auto" inherits the behavior from the CSS scroll-behavior, which is why having the "instant" value is important

  3. BayanBennett commented on Apr 27, 2022

    @BayanBennett
  4. BayanBennett commented on Apr 27, 2022

    @BayanBennett

    More context: It seems like the "instant" value isn't part of the CSSOM spec https://github.com/w3c/csswg-drafts/blob/main/cssom-view-1/Overview.bs#L407

    EDIT: instant is back due to w3c/csswg-drafts#8107, thanks to #47441 (comment) for pointing this out.

  5. zhangenming commented on Feb 28, 2023

    @zhangenming

    8b07e5831d8c3695a2fddbac139c908

    auto and instant behave differently in my browser

  6. YahangWu commented on Mar 29, 2023

    @YahangWu

    This has been restored in cssom w3c/csswg-drafts#8107, please added it back. Thanks :))

  7. curtisburns commented on Mar 31, 2023

    @curtisburns

    Just encountered this issue. Would be great to have this as MDN docs seem to suggest it is an option, and I only get the behaviour I need with instant and not auto which seems to fall back on the CSS style rule if set (I have it set to smooth). Have used 'instant' as ScrollBehavior in the meantime. Cheers.

  8. Teamop commented on Apr 19, 2023

    @Teamop

    it's already fixed in #53133 which was just include in v5.1-beta

  9. cbroomemktw commented on Apr 20, 2023

    @cbroomemktw

    Terry (@Teamop) thanks! For anyone who can't update while still in beta you can brute force this setting as a workaround:

          const scrollToOptions = { top: 0, left: 0, behavior: 'instant' };
          window.scrollTo(scrollToOptions as unknown as ScrollToOptions);
    
  10. DanielRuf commented on Jun 19, 2023

    @DanielRuf

    Note that behavior: "auto" inherits the behavior from the CSS scroll-behavior, which is why having the "instant" value is important

    Exactly.

  11. jakebailey commented on Jul 9, 2023

    @jakebailey
    Member

    As noted in #47441 (comment), this is already fixed and now released in TS 5.1.

  12. helloint commented on Sep 27, 2024

    @helloint

    As noted in #47441 (comment), this is already fixed and now released in TS 5.1.

    Can this small issue being published to latest 4.x? Upgrading to 5.x is a big change to the project and the entire eco

  13. locked as resolved and limited conversation to collaborators on Oct 22, 2025
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

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions