Skip to content

Commit

Permalink
Fix rendering of snacks on route update on mobile (#3463)
Browse files Browse the repository at this point in the history
* Fix rendering of snacks on mobile

Switching pages on mobile currently causes a blank snack example to show.

This is root caused to a workaround on the `onRouteUpdate` to read the DOM after mutation, which seems to work on desktop, but not on the mobile version of the site. This change moves to a newer lifecycle method called after the document is rendered to the DOM, which fixes the issue.

* Update console.log
  • Loading branch information
NickGerleman authored Dec 10, 2022
1 parent 3f087e8 commit 035054c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions website/snackPlayerInitializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,11 @@ export default (() => {
setupThemeSynchronization();

return {
onRouteUpdate({location}) {
// console.log('onRouteUpdate', {location});
onRouteDidUpdate({location}) {
// console.log('onRouteDidUpdate', {location});

// TODO temporary, because onRouteUpdate fires before the new route renders...
// see https://github.com/facebook/docusaurus/issues/3399#issuecomment-704401189
setTimeout(() => {
initSnackPlayers();
setupTabPanelsMutationObservers();
}, 0);
initSnackPlayers();
setupTabPanelsMutationObservers();
},
};
})();

0 comments on commit 035054c

Please sign in to comment.