-
Notifications
You must be signed in to change notification settings - Fork 27.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add runtime to hotUpdateMainFilename (#26256)
Updates the hotUpdateChunk to include `[runtime]` for web workers support. Fixes #26152 Fixes #19865 Fixes #26144 ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. ## Documentation / Examples - [ ] Make sure the linting passes
- Loading branch information
1 parent
98acfaf
commit 88ed526
Showing
11 changed files
with
143 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export function Expensive() { | ||
const start = performance.now() | ||
let i = 99999 | ||
|
||
const bigArray = [] | ||
while (--i) { | ||
bigArray.push(i) | ||
} | ||
|
||
const endTime = performance.now() | ||
|
||
if (typeof window === 'undefined') { | ||
console.log('[WORKER] Completed expensive function in', endTime - start) | ||
} else { | ||
console.log('[WEB] Completed expensive function in', endTime - start) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Expensive } from './sharedCode' | ||
import faker from 'faker' | ||
|
||
// Ensure a large libraries is added so that splitChunks would trigger if enabled. | ||
console.log(faker) | ||
|
||
Expensive() | ||
self.postMessage(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as React from 'react' | ||
import { Expensive } from '../lib/sharedCode' | ||
|
||
export default function Home() { | ||
const [expensiveWebStatus, setExpensiveWebStatus] = React.useState('WAIT') | ||
const [expensiveWorkerStatus, setExpensiveWorkerComplete] = React.useState( | ||
'WAIT' | ||
) | ||
const worker = React.useRef() | ||
|
||
React.useEffect(() => { | ||
worker.current = new Worker(new URL('../lib/worker.js', import.meta.url)) | ||
worker.current.addEventListener('message', ({ data }) => { | ||
if (data) { | ||
setExpensiveWorkerComplete('PASS') | ||
} | ||
}) | ||
worker.current.addEventListener('error', (data) => { | ||
setExpensiveWorkerComplete('FAIL') | ||
}) | ||
}, [worker, setExpensiveWorkerComplete]) | ||
React.useEffect(() => { | ||
try { | ||
Expensive() | ||
setExpensiveWebStatus('PASS') | ||
} catch { | ||
setExpensiveWebStatus('FAIL') | ||
} | ||
}, []) | ||
|
||
return ( | ||
<main> | ||
<h1>$RefreshRegistry repro</h1> | ||
<div id="web-status">Web: {expensiveWebStatus}</div> | ||
<div id="worker-status">Worker: {expensiveWorkerStatus}</div> | ||
</main> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* eslint-env jest */ | ||
import { | ||
check, | ||
findPort, | ||
killApp, | ||
launchApp, | ||
nextStart, | ||
nextBuild, | ||
} from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
import { join } from 'path' | ||
|
||
const appDir = join(__dirname, '../') | ||
|
||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
let appPort | ||
let app | ||
|
||
const runTests = () => { | ||
it('should pass on both client and worker', async () => { | ||
let browser | ||
try { | ||
browser = await webdriver(appPort, '/') | ||
await browser.waitForElementByCss('#web-status') | ||
await check(() => browser.elementByCss('#web-status').text(), /PASS/i) | ||
await browser.waitForElementByCss('#worker-status') | ||
await check(() => browser.elementByCss('#worker-status').text(), /PASS/i) | ||
} finally { | ||
if (browser) { | ||
await browser.close() | ||
} | ||
} | ||
}) | ||
} | ||
|
||
describe('Web Workers with webpack 5', () => { | ||
describe('dev mode', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
|
||
describe('server mode', () => { | ||
beforeAll(async () => { | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8488,6 +8488,11 @@ extsprintf@^1.2.0: | |
version "1.4.0" | ||
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f" | ||
|
||
[email protected]: | ||
version "5.5.3" | ||
resolved "https://registry.yarnpkg.com/faker/-/faker-5.5.3.tgz#c57974ee484431b25205c2c8dc09fda861e51e0e" | ||
integrity sha512-wLTv2a28wjUyWkbnX7u/ABZBkUkIF2fCd73V6P2oFqEGEktDfzWx4UxrSqtPRw0xPRAcjeAOIiJWqZm3pP4u3g== | ||
|
||
fast-deep-equal@^3.1.1: | ||
version "3.1.1" | ||
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz#545145077c501491e33b15ec408c294376e94ae4" | ||
|