Skip to content

Commit

Permalink
Catch animation errors for ::backdrop
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanpingle committed Jul 26, 2023
1 parent dc5b15c commit d766ecb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
26 changes: 16 additions & 10 deletions src/client/lazy-app/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ export default class Modal extends Component<Props, State> {
{ duration: 250, easing: 'ease' },
);
// animate modal::backdrop
animateTo(this.dialogElement, [{ opacity: 0 }, { opacity: 1 }], {
duration: 250,
easing: 'linear',
pseudoElement: '::backdrop',
});
// some browsers don't support ::backdrop, catch those errors
try {
animateTo(this.dialogElement, [{ opacity: 0 }, { opacity: 1 }], {
duration: 250,
easing: 'linear',
pseudoElement: '::backdrop',
});
} catch (e) {}
this.setState({ shown: true });
}

Expand All @@ -75,11 +78,14 @@ export default class Modal extends Component<Props, State> {
{ duration: 250, easing: 'ease' },
);
// animate modal::backdrop
animateTo(this.dialogElement, [{ opacity: 0 }], {
duration: 250,
easing: 'linear',
pseudoElement: '::backdrop',
});
// some browsers don't support ::backdrop, catch those errors
try {
animateTo(this.dialogElement, [{ opacity: 0 }], {
duration: 250,
easing: 'linear',
pseudoElement: '::backdrop',
});
} catch (e) {}
anim.onfinish = this._closeOnTransitionEnd;
}

Expand Down
4 changes: 3 additions & 1 deletion src/client/lazy-app/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export function animateTo(
) {
const anim = element.animate(to, { ...options, fill: 'both' });
anim.addEventListener('finish', () => {
if (!('pseudoElement' in options && options['pseudoElement']))
// pseudo-elements don't support inline styles at the moment, catch those errors
try {
anim.commitStyles();
} catch (e) {}
anim.cancel();
});
return anim;
Expand Down

0 comments on commit d766ecb

Please sign in to comment.