|
4 | 4 | <meta charset="UTF-8" /> |
5 | 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
6 | 6 | <title>Beacons</title> |
7 | | - <!-- Preload polyfill to ensure React is available globally --> |
| 7 | + <!-- CRITICAL: Polyfill to ensure React is available globally --> |
8 | 8 | <script> |
9 | | - // Global React polyfill to prevent errors like: |
10 | | - // - Cannot read properties of undefined (reading 'useLayoutEffect') |
11 | | - // - Cannot read properties of undefined (reading 'createContext') |
12 | | - if (typeof window !== 'undefined') { |
13 | | - window.React = window.React || {}; |
| 9 | + // THIS MUST RUN BEFORE ANY OTHER SCRIPTS |
| 10 | + (function() { |
| 11 | + // Global React polyfill to prevent errors like: |
| 12 | + // - Cannot read properties of undefined (reading 'useLayoutEffect') |
| 13 | + // - Cannot read properties of undefined (reading 'createContext') |
| 14 | + window.React = {}; |
14 | 15 | window.React.useState = function() { return [undefined, function() {}]; }; |
15 | 16 | window.React.useEffect = function() { return function() {}; }; |
16 | 17 | window.React.useLayoutEffect = function() { return function() {}; }; |
17 | 18 | window.React.useRef = function() { return { current: null }; }; |
18 | 19 | window.React.useContext = function() { return {}; }; |
19 | | - window.React.createContext = function() { return { Provider: function() {}, Consumer: function() {} }; }; |
| 20 | + window.React.createContext = function() { return { Provider: function(){}, Consumer: function(){} }; }; |
20 | 21 | window.React.forwardRef = function(fn) { return fn; }; |
21 | | - } |
| 22 | + window.React.Children = { map: function(){}, forEach: function(){}, count: function(){}, only: function(){} }; |
| 23 | + window.React.Fragment = "Fragment"; |
| 24 | + window.React.StrictMode = "StrictMode"; |
| 25 | + window.React.cloneElement = function() { return {}; }; |
| 26 | + window.React.createElement = function() { return {}; }; |
| 27 | + |
| 28 | + // Ensure this polyfill isn't overridden |
| 29 | + Object.defineProperty(window, 'React', { |
| 30 | + configurable: false, |
| 31 | + writable: false |
| 32 | + }); |
| 33 | + })(); |
22 | 34 | </script> |
23 | 35 | </head> |
24 | 36 | <body> |
|
0 commit comments