Files
outline/app/utils/polyfills.ts
T
Tom MoorandClaude Opus 5 fcae7b3c57 fix: Pages fail to load on older browsers (#13450)
* fix: Shared pages fail to load on older browsers

Object.hasOwn is unavailable before Chrome 93 and Safari 15.4, and
es-toolkit calls it directly from isEqualWith, which useActionContext
runs on every render. Add a polyfill applied at module scope, ahead of
the other imports, so it covers dependency evaluation and first render.

Fixes OUTLINE-CLOUD-D0W

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Define the polyfill as non-enumerable to match the native property

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-15 20:14:23 -04:00

49 lines
1.2 KiB
TypeScript

declare global {
interface ObjectConstructor {
hasOwn(target: object, property: PropertyKey): boolean;
}
}
// Applied at module scope so dependencies that call it during evaluation, or on
// first render, are covered. Unavailable before Chrome 93 and Safari 15.4.
if (typeof Object.hasOwn !== "function") {
Object.defineProperty(Object, "hasOwn", {
value: (target: object, property: PropertyKey) =>
Object.prototype.hasOwnProperty.call(target, property),
writable: true,
configurable: true,
});
}
/**
* 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 window &&
"ResizeObserverEntry" in window &&
"contentRect" in ResizeObserverEntry.prototype
);
}