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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Manipulator.offset() #33603

Merged
merged 8 commits into from
Jul 28, 2021
Merged

Fix Manipulator.offset() #33603

merged 8 commits into from
Jul 28, 2021

Conversation

alpadev
Copy link
Contributor

@alpadev alpadev commented Apr 10, 2021

fixes #32496, closes #32341

Background

Manipulator.offset() is using getBoundingClientRect() that returns top/left values relative to the viewport. The current implementation uses document.body.scrollTop and document.body.scrollLeft to get the scroll position of the viewport. (Both returning 0 in current Chrome and FF)

This used to work with older browsers but since then got changed to document.documentElement.scrollTop and document.documentElement.scrollLeft. The currently proposed way to get those values (according to MDN) is to use window.pageYOffset and window.pageXOffset.

TBD

  • Should we also add fallbacks for window.pageYOffset and window.pageXOffset mentioned on the MDN page?

  • Not sure about the test cases. Maybe someone got a better idea how to implement them.

Preview: https://deploy-preview-33603--twbs-bootstrap.netlify.app/docs/5.0/components/scrollspy/

Example of #32496 using the fix: https://codepen.io/-alpa-/pen/MWpVooG

@alpadev alpadev requested a review from a team as a code owner April 10, 2021 07:18
@alpadev alpadev force-pushed the fix-manipulator-offset branch from eae9f25 to 3d14542 Compare April 10, 2021 08:01
@GeoSot
Copy link
Member

GeoSot commented Apr 12, 2021

Alpa, sure is better than before. However check the preview. It fails to initialize in proper element after refresh
EDIT: It starts in the right position. It fails on next scroll, making me suspect the internals of scrollspy

@PetersOtto
Copy link

PetersOtto commented May 11, 2021

Is that issue really fix? I have the same behavior than before. #32496
Perhaps I do something wrong but I think the issue is not gone.

@harnishdesign
Copy link

Issue is still in bootstrap v5.0.1. #32496 have available finally any fixed?

@arcanisgk
Copy link

excuse my ignorance; but if a single DOMContentLoaded is placed; What will happen to the content added with bootstrap ajax, what is expected to have any interaction or effect, will it still work?

@alpadev
Copy link
Contributor Author

alpadev commented Jun 11, 2021

@arcanisgk how is that related?

@GeoSot
Copy link
Member

GeoSot commented Jun 11, 2021

@alpadev Correct me if I am wrong, but Manipulator methods offset & position are used only on scrollSpy, So they maybe can be moved to it

@XhmikosR
Copy link
Member

@alpadev regarding your OP TODO

  1. I don't think our supported browsers don't support scrollY so we should be safe
  2. Not sure about the tests, I trust you, @rohit2sharma95 and @GeoSot :)

If you don't have further changes, we could include this in v5.0.2

@XhmikosR
Copy link
Member

Forgot to mention that if we already use pageYOffset/pageYOffsetY, we could probably use that here too and switch to the other in a separate PR.

@GeoSot GeoSot requested a review from rohit2sharma95 June 22, 2021 09:50
@XhmikosR XhmikosR merged commit 047145e into twbs:main Jul 28, 2021
@XhmikosR
Copy link
Member

XhmikosR commented Aug 3, 2021

@alpadev it seems we are getting random BrowserStack failures:

Mobile Safari 12.1.1 (iOS 12.3.1) Manipulator offset should not change offset when viewport is scrolled FAILED
	Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) in node_modules/jasmine-core/lib/jasmine-core/jasmine.js (line 7741)
	<Jasmine>

Maybe we need some timeout?

@arcanisgk
Copy link

It seems to me not to be completely random, it simply tries to execute at the same time as the resizing/changing the orientation of Mobile, it is not that it needs a time out I think it needs to know the status of the viewport.

@XhmikosR
Copy link
Member

XhmikosR commented Aug 3, 2021

By random I mean it doesn't always happen as you can see by the current test status :)

Anyway, if anyone has any patches, please make a new PR.

@arcanisgk
Copy link

I am almost certain that the event is intercepted in the rotation of a Mobile device:

var supportsOrientationChange = "onorientationchange" in window,
    orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";

window.addEventListener(orientationEvent, function() {
    alert('HOLY ROTATING SCREENS BATMAN:' + window.orientation + " " + screen.width);
}, false);

marvin-hinkley-vortx pushed a commit to Vortx-Inc/bootstrap that referenced this pull request Aug 18, 2021
* test: add more test cases for Manipulator.offset()

* fix: Manipulator.offset() is using obsolete properties to get scroll position

Co-authored-by: XhmikosR <[email protected]>
Co-authored-by: GeoSot <[email protected]>
@XhmikosR
Copy link
Member

@arcanisgk could you make a PR please? We keep hitting the CI failure but it's not 100% reproducible.

@arcanisgk
Copy link

@XhmikosR Hello, I'm sorry to tell you that I don't have the slightest idea what "PR" is; The most I have achieved in github is to create a personal repository upload a library and publish it to be distributed in composer, I would like to help more but I do not have enough knowledge to support them.

@XhmikosR
Copy link
Member

No worries. We need someone to have a look at this issue at some point. I might create a new issue so that this gains more eyes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scrollspy: highlights wrong navigation item when a page is reloaded.
7 participants