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

Block: Fix issues with stories not appearing in lightbox #13493

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions packages/stories-lightbox/src/web-stories-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
this.player.addEventListener('navigation', (event) => {
const storyObject = this.stories[event.detail.index];
if (storyObject && storyObject.href !== document.location.href) {
history.pushState({}, '', storyObject.href);
this.storyContentReady(storyObject, () => {
history.pushState({}, '', storyObject.href);

Check warning on line 62 in packages/stories-lightbox/src/web-stories-lightbox.js

View check run for this annotation

Codecov / codecov/patch

packages/stories-lightbox/src/web-stories-lightbox.js#L61-L62

Added lines #L61 - L62 were not covered by tests
});
}
});

Expand Down Expand Up @@ -127,13 +129,34 @@
this.player.show(storyObject.href);
this.player.play();

history.pushState({}, '', storyObject.href);
this.storyContentReady(storyObject, () => {
history.pushState({}, '', storyObject.href);

Check warning on line 133 in packages/stories-lightbox/src/web-stories-lightbox.js

View check run for this annotation

Codecov / codecov/patch

packages/stories-lightbox/src/web-stories-lightbox.js#L132-L133

Added lines #L132 - L133 were not covered by tests
});

this.lightboxElement.classList.toggle('show');
document.body.classList.toggle('web-stories-lightbox-open');
});
});
}

/**
* Executes supplied `callback` after the story is fully loaded into player.
*
* @param {*} storyObject Story object to check for. Reference: https://github.com/ampproject/amphtml/blob/4ce3cd79520dbeaf5ed5364cbff58d3d71dee40e/src/amp-story-player/amp-story-player-impl.js#L115-L129.
* @param {*} callback Callback to execute when story is loaded fully.
* @param {number} maxRetries Number of tries to check for.
*/
storyContentReady(storyObject, callback, maxRetries = 5) {
const stateIntervalObj = setInterval(() => {
if (storyObject.storyContentLoaded === true) {
window.clearInterval(stateIntervalObj);
callback();

Check warning on line 153 in packages/stories-lightbox/src/web-stories-lightbox.js

View check run for this annotation

Codecov / codecov/patch

packages/stories-lightbox/src/web-stories-lightbox.js#L150-L153

Added lines #L150 - L153 were not covered by tests
}
if (!--maxRetries) {
window.clearInterval(stateIntervalObj);

Check warning on line 156 in packages/stories-lightbox/src/web-stories-lightbox.js

View check run for this annotation

Codecov / codecov/patch

packages/stories-lightbox/src/web-stories-lightbox.js#L155-L156

Added lines #L155 - L156 were not covered by tests
}
}, 250);
}
}

export default function initializeWebStoryLightbox() {
Expand Down
Loading