Skip to content

Commit

Permalink
Ensure React polyfill includes minimal location and navigator pol…
Browse files Browse the repository at this point in the history
…yfills
  • Loading branch information
lemonmade committed Jun 27, 2024
1 parent bf7e30a commit 2b09e04
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-pianos-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remote-dom/react": patch
---

Ensure React polyfill includes minimal `location` and `navigator` polyfills
20 changes: 18 additions & 2 deletions packages/react/source/polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,30 @@ class CSSStyleDeclaration {
}

// React ues the `location` property when printing help text in development.
window.location = globalThis.location;
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.
(window as any).HTMLIFrameElement = HTMLIFrameElement;
Object.defineProperty(window, 'HTMLIFrameElement', {
value: HTMLIFrameElement,
configurable: true,
});

// React checks for a few properties in `document.createElement('div').style`
const STYLE = Symbol('style');
Object.defineProperty(Element.prototype, 'style', {
configurable: true,
get() {
let style = this[STYLE];
if (!style) {
Expand Down

0 comments on commit 2b09e04

Please sign in to comment.