forked from Shopify/remote-dom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix document polyfill executed too late
The polyfill MUST be run before react initializes to be effective.
- Loading branch information
1 parent
dee3089
commit 71de8e2
Showing
2 changed files
with
25 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Make the react build believe that it is running in a page context, | ||
// otherwise react rendering errors won't be logged. This code MUST | ||
// be in the global scope, to ensure that it is run before react | ||
// initializes. This is especially important when bundlers are used | ||
// which will re-order modules by execution priority. | ||
// | ||
// React logic we're working around: | ||
// https://github.com/facebook/react/blob/4e6eec69be632c0c0177c5b1c8a70397d92ee181/packages/shared/invokeGuardedCallbackImpl.js#L53-L237 | ||
if (!('window' in globalThis) && !('document' in globalThis)) { | ||
class FakeDocument { | ||
createEvent(type: string) { | ||
return new Event(type); | ||
} | ||
|
||
createElement() { | ||
return new EventTarget(); | ||
} | ||
} | ||
|
||
globalThis.window = globalThis as any; | ||
globalThis.document = new FakeDocument() as any; | ||
} | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters