Skip to content

Commit a1b11ce

Browse files
add noop refresh runtime to prevent errors after module execution (vercel/turborepo#4701)
### Description We add some noop handlers to make sure code won't throw errors when something tries to access the refresh runtime outside the initial module execution next.js does this here https://github.com/vercel/next.js/blob/f12aa35b0d85aa28223e06ee6f6a98247262815e/packages/react-refresh-utils/ReactRefreshWebpackPlugin.ts#L16-L30 I'm not 100% sure this is the correct fix fix WEB-823
1 parent c7494cd commit a1b11ce

File tree

31 files changed

+248
-0
lines changed

31 files changed

+248
-0
lines changed

crates/turbopack-dev/js/src/runtime.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,14 @@ function runModuleExecutionHooks(module, executeModule) {
458458
cleanupReactRefreshIntercept();
459459
}
460460

461+
// noop fns to prevent refresh runtime errors when trying to access the runtime outside of the initial module execution.
462+
globalThis.$RefreshReg$ = function () {};
463+
globalThis.$RefreshSig$ = function () {
464+
return function (type) {
465+
return type;
466+
};
467+
};
468+
461469
/**
462470
* Retrieves a module from the cache, or instantiate it if it is not cached.
463471
*

crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_0d348e.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ function runModuleExecutionHooks(module, executeModule) {
467467
cleanupReactRefreshIntercept();
468468
}
469469

470+
// noop fns to prevent refresh runtime errors when trying to access the runtime outside of the initial module execution.
471+
globalThis.$RefreshReg$ = function () {};
472+
globalThis.$RefreshSig$ = function () {
473+
return function (type) {
474+
return type;
475+
};
476+
};
477+
470478
/**
471479
* Retrieves a module from the cache, or instantiate it if it is not cached.
472480
*

crates/turbopack-tests/tests/snapshot/basic/chunked/output/crates_turbopack-tests_tests_snapshot_basic_chunked_input_index_e77e9f.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ function runModuleExecutionHooks(module, executeModule) {
467467
cleanupReactRefreshIntercept();
468468
}
469469

470+
// noop fns to prevent refresh runtime errors when trying to access the runtime outside of the initial module execution.
471+
globalThis.$RefreshReg$ = function () {};
472+
globalThis.$RefreshSig$ = function () {
473+
return function (type) {
474+
return type;
475+
};
476+
};
477+
470478
/**
471479
* Retrieves a module from the cache, or instantiate it if it is not cached.
472480
*

crates/turbopack-tests/tests/snapshot/basic/shebang/output/crates_turbopack-tests_tests_snapshot_basic_shebang_input_index_b1f0c2.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ function runModuleExecutionHooks(module, executeModule) {
467467
cleanupReactRefreshIntercept();
468468
}
469469

470+
// noop fns to prevent refresh runtime errors when trying to access the runtime outside of the initial module execution.
471+
globalThis.$RefreshReg$ = function () {};
472+
globalThis.$RefreshSig$ = function () {
473+
return function (type) {
474+
return type;
475+
};
476+
};
477+
470478
/**
471479
* Retrieves a module from the cache, or instantiate it if it is not cached.
472480
*

crates/turbopack-tests/tests/snapshot/comptime/define/output/crates_turbopack-tests_tests_snapshot_comptime_define_input_index_6b0d2b.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ function runModuleExecutionHooks(module, executeModule) {
467467
cleanupReactRefreshIntercept();
468468
}
469469

470+
// noop fns to prevent refresh runtime errors when trying to access the runtime outside of the initial module execution.
471+
globalThis.$RefreshReg$ = function () {};
472+
globalThis.$RefreshSig$ = function () {
473+
return function (type) {
474+
return type;
475+
};
476+
};
477+
470478
/**
471479
* Retrieves a module from the cache, or instantiate it if it is not cached.
472480
*

crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/output/crates_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_fa9a30.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ function runModuleExecutionHooks(module, executeModule) {
467467
cleanupReactRefreshIntercept();
468468
}
469469

470+
// noop fns to prevent refresh runtime errors when trying to access the runtime outside of the initial module execution.
471+
globalThis.$RefreshReg$ = function () {};
472+
globalThis.$RefreshSig$ = function () {
473+
return function (type) {
474+
return type;
475+
};
476+
};
477+
470478
/**
471479
* Retrieves a module from the cache, or instantiate it if it is not cached.
472480
*

crates/turbopack-tests/tests/snapshot/css/css/output/crates_turbopack-tests_tests_snapshot_css_css_input_index_37a138.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ function runModuleExecutionHooks(module, executeModule) {
467467
cleanupReactRefreshIntercept();
468468
}
469469

470+
// noop fns to prevent refresh runtime errors when trying to access the runtime outside of the initial module execution.
471+
globalThis.$RefreshReg$ = function () {};
472+
globalThis.$RefreshSig$ = function () {
473+
return function (type) {
474+
return type;
475+
};
476+
};
477+
470478
/**
471479
* Retrieves a module from the cache, or instantiate it if it is not cached.
472480
*

crates/turbopack-tests/tests/snapshot/emotion/emotion/output/crates_turbopack-tests_tests_snapshot_emotion_emotion_input_index_b080c4.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ function runModuleExecutionHooks(module, executeModule) {
467467
cleanupReactRefreshIntercept();
468468
}
469469

470+
// noop fns to prevent refresh runtime errors when trying to access the runtime outside of the initial module execution.
471+
globalThis.$RefreshReg$ = function () {};
472+
globalThis.$RefreshSig$ = function () {
473+
return function (type) {
474+
return type;
475+
};
476+
};
477+
470478
/**
471479
* Retrieves a module from the cache, or instantiate it if it is not cached.
472480
*

crates/turbopack-tests/tests/snapshot/env/env/output/crates_turbopack-tests_tests_snapshot_env_env_input_index_29a23f.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ function runModuleExecutionHooks(module, executeModule) {
467467
cleanupReactRefreshIntercept();
468468
}
469469

470+
// noop fns to prevent refresh runtime errors when trying to access the runtime outside of the initial module execution.
471+
globalThis.$RefreshReg$ = function () {};
472+
globalThis.$RefreshSig$ = function () {
473+
return function (type) {
474+
return type;
475+
};
476+
};
477+
470478
/**
471479
* Retrieves a module from the cache, or instantiate it if it is not cached.
472480
*

crates/turbopack-tests/tests/snapshot/evaluated_entrry/runtime_entry/output/a587c_tests_snapshot_evaluated_entrry_runtime_entry_input_index_f59cc7.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ function runModuleExecutionHooks(module, executeModule) {
467467
cleanupReactRefreshIntercept();
468468
}
469469

470+
// noop fns to prevent refresh runtime errors when trying to access the runtime outside of the initial module execution.
471+
globalThis.$RefreshReg$ = function () {};
472+
globalThis.$RefreshSig$ = function () {
473+
return function (type) {
474+
return type;
475+
};
476+
};
477+
470478
/**
471479
* Retrieves a module from the cache, or instantiate it if it is not cached.
472480
*

0 commit comments

Comments
 (0)