-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: webSocket stats message conflict when multiple web environment (#…
…2989) Co-authored-by: neverland <[email protected]>
- Loading branch information
1 parent
4608236
commit 6b3770f
Showing
11 changed files
with
247 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import fs from 'node:fs'; | ||
import { join } from 'node:path'; | ||
import { dev, gotoPage, rspackOnlyTest } from '@e2e/helper'; | ||
import { expect, test } from '@playwright/test'; | ||
import { pluginReact } from '@rsbuild/plugin-react'; | ||
|
||
const cwd = __dirname; | ||
|
||
rspackOnlyTest( | ||
'Multiple environments HMR should work correctly', | ||
async ({ page, context }) => { | ||
// HMR cases will fail in Windows | ||
if (process.platform === 'win32') { | ||
test.skip(); | ||
} | ||
|
||
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), { | ||
recursive: true, | ||
}); | ||
|
||
const rsbuild = await dev({ | ||
cwd, | ||
rsbuildConfig: { | ||
plugins: [pluginReact()], | ||
environments: { | ||
web: { | ||
source: { | ||
entry: { | ||
index: join(cwd, 'test-temp-src/index.ts'), | ||
}, | ||
}, | ||
}, | ||
web1: { | ||
dev: { | ||
// When generating outputs for multiple web environments, | ||
// if assetPrefix is not added, file search conflicts will occur. | ||
assetPrefix: 'auto', | ||
}, | ||
source: { | ||
entry: { | ||
main: join(cwd, 'test-temp-src/web1.js'), | ||
}, | ||
}, | ||
output: { | ||
distPath: { | ||
root: 'dist/web1', | ||
html: 'html1', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const web1Page = await context.newPage(); | ||
|
||
await web1Page.goto(`http://localhost:${rsbuild.port}/web1/html1/main`); | ||
|
||
const locator1 = web1Page.locator('#test'); | ||
await expect(locator1).toHaveText('Hello Rsbuild (web1)!'); | ||
|
||
await gotoPage(page, rsbuild); | ||
|
||
const locator = page.locator('#test'); | ||
await expect(locator).toHaveText('Hello Rsbuild!'); | ||
await expect(locator).toHaveCSS('color', 'rgb(255, 0, 0)'); | ||
|
||
const locatorKeep = page.locator('#test-keep'); | ||
const keepNum = await locatorKeep.innerHTML(); | ||
|
||
// web1 live reload correctly and should not trigger index update | ||
const web1JSPath = join(cwd, 'test-temp-src/web1.js'); | ||
|
||
await fs.promises.writeFile( | ||
web1JSPath, | ||
fs.readFileSync(web1JSPath, 'utf-8').replace('(web1)', '(web1-new)'), | ||
); | ||
|
||
await expect(locator1).toHaveText('Hello Rsbuild (web1)!'); | ||
|
||
await expect(locatorKeep.innerHTML()).resolves.toBe(keepNum); | ||
|
||
// index hmr correctly | ||
const appPath = join(cwd, 'test-temp-src/App.tsx'); | ||
|
||
await fs.promises.writeFile( | ||
appPath, | ||
fs.readFileSync(appPath, 'utf-8').replace('Hello Rsbuild', 'Hello Test'), | ||
); | ||
|
||
await expect(locator).toHaveText('Hello Test!'); | ||
|
||
// #test-keep should unchanged when app.tsx HMR | ||
await expect(locatorKeep.innerHTML()).resolves.toBe(keepNum); | ||
|
||
await rsbuild.close(); | ||
}, | ||
); |
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,3 @@ | ||
#test { | ||
color: rgb(255, 0, 0); | ||
} |
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,4 @@ | ||
import './App.css'; | ||
|
||
const App = () => <div id="test">Hello Rsbuild!</div>; | ||
export default App; |
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 @@ | ||
import React from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
import App from './App'; | ||
|
||
const num = Math.ceil(Math.random() * 100); | ||
const testEl = document.createElement('div'); | ||
testEl.id = 'test-keep'; | ||
|
||
testEl.innerHTML = String(num); | ||
|
||
document.body.appendChild(testEl); | ||
|
||
const container = document.getElementById('root'); | ||
if (container) { | ||
const root = createRoot(container); | ||
root.render(React.createElement(App)); | ||
} |
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,5 @@ | ||
const testEl = document.createElement('div'); | ||
testEl.id = 'test'; | ||
testEl.innerHTML = 'Hello Rsbuild (web1)!'; | ||
|
||
document.body.appendChild(testEl); |
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
Oops, something went wrong.