Skip to content

Commit

Permalink
Apply React polyfill directly to globalThis
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonmade committed Nov 14, 2024
1 parent 4a2242e commit b4e67ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-frogs-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@remote-dom/react': patch
---

Apply React polyfill directly to `globalThis`
21 changes: 3 additions & 18 deletions packages/react/source/polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {window} from '@remote-dom/core/polyfill';

class HTMLIFrameElement extends HTMLElement {}

class CSSStyleDeclaration {
Expand All @@ -24,23 +22,8 @@ class CSSStyleDeclaration {
}
}

// React ues the `location` property when printing help text in development.
if (!window.location) {
Object.defineProperty(window, 'location', {
value: globalThis.location ?? {protocol: 'https:'},
configurable: true,
});
}

if (!window.navigator) {
Object.defineProperty(window, 'navigator', {
value: globalThis.navigator ?? {userAgent: ''},
configurable: true,
});
}

// React checks whether elements are Iframes on initialization.
Object.defineProperty(window, 'HTMLIFrameElement', {
Object.defineProperty(globalThis, 'HTMLIFrameElement', {
value: HTMLIFrameElement,
configurable: true,
});
Expand All @@ -61,3 +44,5 @@ Object.defineProperty(Element.prototype, 'style', {
this.style.cssText = String(cssText);
},
});

export {};

0 comments on commit b4e67ce

Please sign in to comment.