Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewportScroller getScrollPosition does not work in Internet Explorer #27957

Closed
pcroc opened this issue Jan 7, 2019 · 5 comments
Closed

ViewportScroller getScrollPosition does not work in Internet Explorer #27957

pcroc opened this issue Jan 7, 2019 · 5 comments
Labels
area: common Issues related to APIs in the @angular/common package freq2: medium P4 A relatively minor issue that is not relevant to core functions risk: low state: confirmed state: has PR type: bug/fix
Milestone

Comments

@pcroc
Copy link

pcroc commented Jan 7, 2019

馃悶 bug report

Affected Package

The issue is caused by package @angular/common

Is this a regression?

No

Description

viewportScroller.getScrollPosition() returns [null,null] in Internet Explorer

馃敩 Minimal Reproduction

https://stackblitz.com/edit/angular-issue-repro2-b8ydqs

View in Internet Explorer 11

馃敟 Exception or Error

Scroll position: [ null, null ]

馃實 Your Environment

Angular Version:


Angular CLI: 6.1.2
Node: 8.11.1
OS: linux x64
Angular: 6.1.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.7.2
@angular-devkit/build-angular     0.7.2
@angular-devkit/build-optimizer   0.7.2
@angular-devkit/build-webpack     0.7.2
@angular-devkit/core              0.7.2
@angular-devkit/schematics        0.7.2
@angular/cli                      6.1.2
@ngtools/webpack                  6.1.2
@schematics/angular               0.7.2
@schematics/update                0.7.2
rxjs                              6.2.2
typescript                        2.9.2
webpack                           4.9.2

Anything else relevant?
Tried Internet Explorer 11

@skreborn
Copy link
Contributor

skreborn commented Jan 7, 2019

This happens because BrowserViewportScroller.getScrollPosition returns with the values window.scrollX and window.scrollY, neither of which are supported by Internet Explorer.

This seems to be incorrectly feature-detected earlier in the function by BrowserViewportScroller.supportScrollRestoration, which returns true for IE11, as both window itself and window.scrollTo are defined. This, however, doesn't check for the availability of the scrollX and scrollY properties.

@kara kara added the area: common Issues related to APIs in the @angular/common package label Jan 7, 2019
@ngbot ngbot bot added this to the needsTriage milestone Jan 7, 2019
@enten
Copy link

enten commented Feb 28, 2019

Why not update ViewportScroller to get viewport scroll position like material2?

--

In-app fix: adding a polyfill in src/polyfills.ts for window.scrollX and window.scrollY can "fix" the issue (for the browser target) with the current ViewportScroller implementation.

Example for IE11:

// src/polyfills
if (!('scrollX' in window)) {
  Object.defineProperty(window, 'scrollX', { get: () => window.pageXOffset });
}

if (!('scrollY' in window)) {
  Object.defineProperty(window, 'scrollY', { get: () => window.pageYOffset });
}

@petebacondarwin
Copy link
Member

petebacondarwin commented May 28, 2020

It seems to me that it would be enough to use the this.window.pageXOffset and this.window.pageYOffset properties instead.

From https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollX#Notes

The pageXOffset property is an alias for the scrollX property:

window.pageXOffset == window.scrollX; // always true
For cross-browser compatibility, use window.pageXOffset instead of window.scrollX.

These properties are supported by IE9-11: https://developer.mozilla.org/en-US/docs/Web/API/Window/pageXOffset#Browser_compatibility

@jelbourn jelbourn added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Oct 1, 2020
@ngbot ngbot bot modified the milestones: Backlog, needsTriage Oct 1, 2020
@jelbourn jelbourn added the P4 A relatively minor issue that is not relevant to core functions label Oct 1, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Oct 1, 2020
@AndrewKushnir
Copy link
Contributor

FYI, the corresponding PR #28262 that contains the fix was merged, so I'm closing this ticket. The fix should be available once the next release (11.0.3) is published. Thank you.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: common Issues related to APIs in the @angular/common package freq2: medium P4 A relatively minor issue that is not relevant to core functions risk: low state: confirmed state: has PR type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants