Skip to content

Commit

Permalink
increase robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
martrapp committed Aug 15, 2024
1 parent c90d8be commit 81315a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-bees-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vtbag/inspection-chamber': patch
---

Fix error on browsers without native view transition API.
13 changes: 7 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function initSpecimen() {
function monkeyPatchStartViewTransition() {
const originalStartViewTransition = frameDocument.startViewTransition;
if (
!originalStartViewTransition ||
originalStartViewTransition.toString() !== 'function startViewTransition() { [native code] }'
)
return;
Expand Down Expand Up @@ -86,7 +87,7 @@ function prePageReveal(e: Event) {
function pageReveal() {
DEBUG && console.log('pageReveal');
if (inspectionChamber.viewTransition) {
observeRenderBlocking();
// observeRenderBlocking();
forceAnimations();
beforeUpdateCallbackDone();
}
Expand All @@ -99,22 +100,22 @@ function observeRenderBlocking() {
console.log(`${(entry.renderBlockingStatus as string).toUpperCase()}: ${entry.name}`);
});
});
observer.observe({ type: "resource", buffered: true });
observer.observe({ type: 'resource', buffered: true });
}

function beforeUpdateCallbackDone() {
setVtActive();
const root = top!.document.documentElement;
const viewTransition = inspectionChamber.viewTransition!;
const modusFunction: Record<Modus, () => void> = {
bypass: () => { },
bypass: () => {},
'slow-motion': setupSlowMotionPlay,
'full-control': controlledPlay,
compare: () => { },
compare: () => {},
};
const modus = getModus();

viewTransition.updateCallbackDone.catch(() => { });
viewTransition.updateCallbackDone.catch(() => {});

viewTransition.ready
.then(async () => {
Expand All @@ -133,7 +134,7 @@ function beforeUpdateCallbackDone() {
top!.history.replaceState(history.state, '', self.location.href);
top!.document.title = titleLogo + ' ' + self.document.title;
})
.finally(() => { });
.finally(() => {});

viewTransition!.finished.finally(() => {
clearVtActive();
Expand Down

0 comments on commit 81315a3

Please sign in to comment.