Repository navigation
Stop the modal overlay from polling every frame while idle #3599
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
chuckcarpenter
wants to merge
5
commits into
main
Choose a base branch
from
fix/modal-overlay-idle
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+463
−28
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fa72ad5
Stop the modal overlay from polling every frame while idle
chuckcarpenter cac3a56
Track scroll parents and stepless overlays without polling
chuckcarpenter 8a1adde
Re-arm move detection when a tracked element resizes
chuckcarpenter a8993d7
Track border-box and inline size changes without polling
chuckcarpenter 0e2c585
Cover overlay tracking end to end in Cypress
chuckcarpenter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <link rel="stylesheet" href="../../../dist/css/shepherd.css" /> | ||
| <script type="module"> | ||
| import Shepherd from '../../../dist/js/shepherd.mjs'; | ||
| window.Shepherd = Shepherd; | ||
| </script> | ||
| </head> | ||
|
|
||
| <body> | ||
| <style> | ||
| body { | ||
| margin: 0; | ||
| } | ||
|
|
||
| .scroller { | ||
| position: fixed; | ||
| left: 100px; | ||
| top: 100px; | ||
| width: 300px; | ||
| height: 200px; | ||
| overflow: auto; | ||
| /* Anchoring would scroll the content back and fire a scroll event. */ | ||
| overflow-anchor: none; | ||
| } | ||
|
|
||
| .content { | ||
| padding-top: 200px; | ||
| height: 600px; | ||
| } | ||
|
|
||
| .in-scroller { | ||
| width: 120px; | ||
| height: 40px; | ||
| background: #ccd; | ||
| } | ||
|
|
||
| .bordered { | ||
| position: fixed; | ||
| left: 500px; | ||
| top: 100px; | ||
| width: 120px; | ||
| height: 40px; | ||
| border: 6px solid #333; | ||
| } | ||
|
|
||
| .line { | ||
| position: fixed; | ||
| left: 500px; | ||
| top: 300px; | ||
| margin: 0; | ||
| white-space: nowrap; | ||
| } | ||
| </style> | ||
|
|
||
| <div class="scroller"> | ||
| <div class="content"><div class="in-scroller"></div></div> | ||
| </div> | ||
| <div class="bordered"></div> | ||
| <p class="line">x<a class="inline" href="#">a long inline target</a></p> | ||
| </body> | ||
| </html> |
127 changes: 127 additions & 0 deletions
127
shepherd.js/test/cypress/integration/overlay-tracking.cy.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import setupTour from '../utils/setup-tour'; | ||
| import overlayOpenings from '../utils/overlay-openings'; | ||
|
|
||
| // End-to-end guard for the overlay following its highlight without polling. | ||
| // Each change here fires no scroll or resize event, and what it does to the | ||
| // highlight depends on layout, which happy-dom does not implement. | ||
| describe('modal overlay tracking', () => { | ||
| let Shepherd, tour; | ||
|
|
||
| beforeEach(() => { | ||
| Shepherd = null; | ||
|
|
||
| cy.visit('/test/cypress/examples/overlay-tracking', { | ||
| onLoad(contentWindow) { | ||
| if (contentWindow.Shepherd) { | ||
| return (Shepherd = contentWindow.Shepherd); | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| tour?.complete(); | ||
| }); | ||
|
|
||
| const startTour = (selector) => { | ||
| cy.document().then(() => { | ||
| tour = setupTour( | ||
| Shepherd, | ||
| { scrollTo: false }, | ||
| () => [ | ||
| { | ||
| attachTo: { element: selector, on: 'bottom' }, | ||
| id: 'tracking', | ||
| text: 'Tracking' | ||
| } | ||
| ], | ||
| { useModalOverlay: true } | ||
| ); | ||
| tour.start(); | ||
| }); | ||
| cy.wait(250); | ||
| }; | ||
|
|
||
| it('re-crops when a scroll parent moves while its target stays put', () => { | ||
| cy.document().then((doc) => { | ||
| doc.querySelector('.scroller').scrollTop = 100; | ||
| }); | ||
| startTour('.in-scroller'); | ||
|
|
||
| cy.document().then((doc) => { | ||
| const scroller = doc.querySelector('.scroller'); | ||
| const target = doc.querySelector('.in-scroller'); | ||
| const { top } = target.getBoundingClientRect(); | ||
| expect(overlayOpenings(doc)[0].height).to.be.closeTo(40, 1); | ||
|
|
||
| // The scroller's top edge moves 20px past the target, and the content | ||
| // above the target moves up by as much, so only the crop changes. | ||
| const shift = top - scroller.getBoundingClientRect().top + 20; | ||
| scroller.style.top = `${100 + shift}px`; | ||
| doc.querySelector('.content').style.paddingTop = `${200 - shift}px`; | ||
| }); | ||
| cy.wait(150); | ||
|
|
||
| cy.document().then((doc) => { | ||
| const target = doc.querySelector('.in-scroller').getBoundingClientRect(); | ||
| const [opening] = overlayOpenings(doc); | ||
|
|
||
| expect(target.top).to.be.closeTo(200, 1); | ||
| expect(opening.y).to.be.closeTo(220, 1); | ||
| expect(opening.height).to.be.closeTo(20, 1); | ||
| }); | ||
| }); | ||
|
|
||
| it('shrinks with a target that loses its border', () => { | ||
| startTour('.bordered'); | ||
|
|
||
| cy.document().then((doc) => { | ||
| expect(overlayOpenings(doc)[0].height).to.be.closeTo(52, 1); | ||
| doc.querySelector('.bordered').style.borderWidth = '0'; | ||
| }); | ||
| cy.wait(150); | ||
|
|
||
| cy.document().then((doc) => { | ||
| const [opening] = overlayOpenings(doc); | ||
|
|
||
| expect(opening.height).to.be.closeTo(40, 1); | ||
| expect(opening.width).to.be.closeTo(120, 1); | ||
| }); | ||
| }); | ||
|
|
||
| it('follows an inline target whose text shrinks', () => { | ||
| startTour('.inline'); | ||
|
|
||
| cy.document().then((doc) => { | ||
| doc.querySelector('.inline').textContent = 'short'; | ||
| }); | ||
| cy.wait(150); | ||
|
|
||
| cy.document().then((doc) => { | ||
| const target = doc.querySelector('.inline').getBoundingClientRect(); | ||
| const [opening] = overlayOpenings(doc); | ||
|
|
||
| expect(opening.x).to.be.closeTo(target.left, 1); | ||
| expect(opening.width).to.be.closeTo(target.width, 1); | ||
| }); | ||
| }); | ||
|
|
||
| it('asks for no frames while nothing moves', () => { | ||
| startTour('.bordered'); | ||
| cy.wait(1000); | ||
|
|
||
| cy.window().then((win) => { | ||
| const { requestAnimationFrame } = win; | ||
| let frames = 0; | ||
| win.requestAnimationFrame = (callback) => { | ||
| frames++; | ||
| return requestAnimationFrame.call(win, callback); | ||
| }; | ||
|
|
||
| cy.wait(1000).then(() => { | ||
| win.requestAnimationFrame = requestAnimationFrame; | ||
| expect(frames).to.equal(0); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retry geometry assertions instead of relying on fixed delays.
If observer delivery takes more than 150 ms, the assertions in
.then()run before the overlay updates and the test fails. The border and inline tests have the same risk. Use retryable.should()assertions after each change.