fix: Lazily polyfill ResizeObserver for old iOS (#3629)

* fix: Lazily polyfill ResizeObserver for old iOS

* fix: Prevent child rendering until polyfills are loaded

* tsc
This commit is contained in:
Tom Moor
2022-06-04 09:06:07 -07:00
committed by GitHub
parent 6fc608c8c1
commit 4eb3b61c7a
5 changed files with 75 additions and 12 deletions

31
app/utils/polyfills.ts Normal file
View File

@@ -0,0 +1,31 @@
/**
* Loads required polyfills.
*
* @returns A promise that resolves when all required polyfills are loaded
*/
export async function loadPolyfills() {
const polyfills = [];
if (!supportsResizeObserver()) {
polyfills.push(
import("@juggle/resize-observer").then((module) => {
window.ResizeObserver = module.ResizeObserver;
})
);
}
return Promise.all(polyfills);
}
/**
* Detect ResizeObserver compatability.
*
* @returns true if the current browser supports ResizeObserver
*/
function supportsResizeObserver() {
return (
"ResizeObserver" in global &&
"ResizeObserverEntry" in global &&
"contentRect" in ResizeObserverEntry.prototype
);
}