Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/utils/getRefreshGlobal.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ function getRefreshGlobal(runtimeTemplate = FALLBACK_RUNTIME_TEMPLATE) {
return Template.asString([
`${refreshGlobal} = {`,
Template.indent([
// Initialise the global with stubs.
// This is to ensure unwanted calls to these functions would not error out.
// If the module is processed by our loader,
// they will be mutated in place during module initialisation by the `setup` function below.
`register: ${runtimeTemplate.returningFunction('undefined')},`,
`signature: ${runtimeTemplate.returningFunction(
runtimeTemplate.returningFunction('type', 'type')
)},`,
`setup: ${runtimeTemplate.basicFunction('currentModuleId', [
// Store all previous values for fields on `refreshGlobal` -
// this allows proper restoration in the `cleanup` phase.
Expand Down
4 changes: 4 additions & 0 deletions test/unit/getRefreshGlobal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe('getRefreshGlobal', () => {
const refreshGlobalTemplate = getRefreshGlobal();
expect(refreshGlobalTemplate).toMatchInlineSnapshot(`
"__webpack_require__.$Refresh$ = {
register: function() { return undefined; },
signature: function() { return function(type) { return type; }; },
setup: function(currentModuleId) {
var prevModuleId = __webpack_require__.$Refresh$.moduleId;
var prevRuntime = __webpack_require__.$Refresh$.runtime;
Expand Down Expand Up @@ -73,6 +75,8 @@ describe('getRefreshGlobal', () => {
);
expect(refreshGlobalTemplate).toMatchInlineSnapshot(`
"__webpack_require__.$Refresh$ = {
register: () => (undefined),
signature: () => ((type) => (type)),
setup: (currentModuleId) => {
const prevModuleId = __webpack_require__.$Refresh$.moduleId;
const prevRuntime = __webpack_require__.$Refresh$.runtime;
Expand Down