diff --git a/lib/index.js b/lib/index.js index db5196ef..ca56b69d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -71,22 +71,6 @@ class ReactRefreshPlugin { } const integrationEntry = getIntegrationEntry(this.options.overlay.sockIntegration); - const socketEntryData = []; - compiler.hooks.make.tap( - { name: this.constructor.name, stage: Number.POSITIVE_INFINITY }, - (compilation) => { - // Exhaustively search all entries for `integrationEntry`. - // If found, mark those entries and the index of `integrationEntry`. - for (const [name, entryData] of compilation.entries.entries()) { - const index = entryData.dependencies.findIndex( - (dep) => dep.request && dep.request.includes(integrationEntry) - ); - if (index !== -1) { - socketEntryData.push({ name, index }); - } - } - } - ); // Overlay entries need to be injected AFTER integration's entry, // so we will loop through everything in `finishMake` instead of `make`. @@ -103,6 +87,17 @@ class ReactRefreshPlugin { return Promise.resolve(); } + // Derive integration positions from this compilation, not previous rebuilds. + const socketEntryData = []; + for (const [name, entryData] of compilation.entries.entries()) { + const index = entryData.dependencies.findIndex( + (dep) => dep.request && dep.request.includes(integrationEntry) + ); + if (index !== -1) { + socketEntryData.push({ name, index }); + } + } + const injectData = socketEntryData.length ? socketEntryData : [{ name: undefined }]; return Promise.all( injectData.map(({ name, index }) => {