|
1 | 1 | var Refresh = require('react-refresh/runtime');
|
2 |
| -var {version} = require('react-refresh/package.json'); |
3 | 2 |
|
4 | 3 | function debounce(func, delay) {
|
5 | 4 | if (process.env.NODE_ENV === 'test') {
|
@@ -33,24 +32,42 @@ var enqueueUpdate = debounce(function () {
|
33 | 32 | Refresh.performReactRefresh();
|
34 | 33 | }, 30);
|
35 | 34 |
|
| 35 | +module.exports.init = function () { |
| 36 | + if (!globalThis.$RefreshReg$) { |
| 37 | + Refresh.injectIntoGlobalHook(globalThis); |
| 38 | + globalThis.$RefreshReg$ = function () {}; |
| 39 | + globalThis.$RefreshSig$ = function () { |
| 40 | + return function (type) { |
| 41 | + return type; |
| 42 | + }; |
| 43 | + }; |
| 44 | + |
| 45 | + if (typeof window !== 'undefined') { |
| 46 | + let ErrorOverlay = require('react-error-overlay'); |
| 47 | + ErrorOverlay.setEditorHandler(function editorHandler(errorLocation) { |
| 48 | + let file = `${errorLocation.fileName}:${ |
| 49 | + errorLocation.lineNumber || 1 |
| 50 | + }:${errorLocation.colNumber || 1}`; |
| 51 | + fetch(`/__parcel_launch_editor?file=${encodeURIComponent(file)}`); |
| 52 | + }); |
| 53 | + |
| 54 | + ErrorOverlay.startReportingRuntimeErrors({ |
| 55 | + onError: function () {}, |
| 56 | + }); |
| 57 | + |
| 58 | + window.addEventListener('parcelhmraccept', () => { |
| 59 | + ErrorOverlay.dismissRuntimeErrors(); |
| 60 | + }); |
| 61 | + } |
| 62 | + } |
| 63 | +}; |
| 64 | + |
36 | 65 | // Everything below is either adapted or copied from
|
37 | 66 | // https://github.com/facebook/metro/blob/61de16bd1edd7e738dd0311c89555a644023ab2d/packages/metro/src/lib/polyfills/require.js
|
38 | 67 | // MIT License - Copyright (c) Facebook, Inc. and its affiliates.
|
39 | 68 |
|
40 | 69 | module.exports.prelude = function (module) {
|
41 |
| - globalThis.__REACT_REFRESH_VERSION_TRANSFORMER = version; |
42 | 70 | globalThis.$RefreshReg$ = function (type, id) {
|
43 |
| - if ( |
44 |
| - globalThis.__REACT_REFRESH_VERSION_TRANSFORMER && |
45 |
| - globalThis.__REACT_REFRESH_VERSION_RUNTIME && |
46 |
| - globalThis.__REACT_REFRESH_VERSION_TRANSFORMER !== |
47 |
| - globalThis.__REACT_REFRESH_VERSION_RUNTIME |
48 |
| - ) { |
49 |
| - // Both versions were set and they did not match |
50 |
| - throw new Error( |
51 |
| - `react-refresh versions did not match between transformer and runtime. Please check your dependencies. Transformer: ${globalThis.__REACT_REFRESH_VERSION_TRANSFORMER}, Runtime: ${globalThis.__REACT_REFRESH_VERSION_RUNTIME}`, |
52 |
| - ); |
53 |
| - } |
54 | 71 | Refresh.register(type, module.id + ' ' + id);
|
55 | 72 | };
|
56 | 73 | globalThis.$RefreshSig$ = Refresh.createSignatureFunctionForTransform;
|
|
0 commit comments