diff --git a/e2e/cases/server/setup-middlewares/index.test.ts b/e2e/cases/server/setup-middlewares/index.test.ts index 692fc5a943..525fc7d7f6 100644 --- a/e2e/cases/server/setup-middlewares/index.test.ts +++ b/e2e/cases/server/setup-middlewares/index.test.ts @@ -23,7 +23,7 @@ test('setupMiddlewares', async ({ page }) => { i++; next(); }); - reloadFn = () => server.sockWrite('content-changed'); + reloadFn = () => server.sockWrite('static-changed'); }, ], }, diff --git a/packages/core/src/server/compilerDevMiddleware.ts b/packages/core/src/server/compilerDevMiddleware.ts index 314bdc52c1..7747ed9ffc 100644 --- a/packages/core/src/server/compilerDevMiddleware.ts +++ b/packages/core/src/server/compilerDevMiddleware.ts @@ -163,7 +163,7 @@ export class CompilerDevMiddleware { // reload page when HTML template changed if (typeof fileName === 'string' && HTML_REGEX.test(fileName)) { this.socketServer.sockWrite({ - type: 'content-changed', + type: 'static-changed', compilationId, }); return; diff --git a/packages/core/src/server/socketServer.ts b/packages/core/src/server/socketServer.ts index fad772e5c2..aa61787963 100644 --- a/packages/core/src/server/socketServer.ts +++ b/packages/core/src/server/socketServer.ts @@ -260,7 +260,7 @@ export class SocketServer { if (shouldReload) { return this.sockWrite({ - type: 'content-changed', + type: 'static-changed', compilationId, }); } diff --git a/website/docs/en/config/dev/setup-middlewares.mdx b/website/docs/en/config/dev/setup-middlewares.mdx index a471922860..17b3fd5645 100644 --- a/website/docs/en/config/dev/setup-middlewares.mdx +++ b/website/docs/en/config/dev/setup-middlewares.mdx @@ -58,7 +58,7 @@ In the `setupMiddlewares` function, you can access the `server` object, which pr `sockWrite` allows middlewares to send some message to HMR client, and then the HMR client will take different actions depending on the message type. -For example, if you send a `'content-changed'` message, the page will reload. +For example, if you send a `'static-changed'` message, the page will reload. ```js export default { @@ -66,7 +66,7 @@ export default { setupMiddlewares: [ (middlewares, server) => { if (someCondition) { - server.sockWrite('content-changed'); + server.sockWrite('static-changed'); } }, ], @@ -74,6 +74,8 @@ export default { }; ``` +> Sending `content-changed` and `static-changed` have the same effect. Since `content-changed` has been deprecated, please use `static-changed` instead. + ### environments `environments` includes Rsbuild's [environment API](/api/javascript-api/environment-api#environment-api), which allows you to get the build outputs information for a specific environment in the server side. diff --git a/website/docs/zh/config/dev/setup-middlewares.mdx b/website/docs/zh/config/dev/setup-middlewares.mdx index 09c163a3e1..12aaa1da22 100644 --- a/website/docs/zh/config/dev/setup-middlewares.mdx +++ b/website/docs/zh/config/dev/setup-middlewares.mdx @@ -58,7 +58,7 @@ export default { `sockWrite` 允许中间件向 HMR 客户端传递一些消息,HMR 客户端将根据接收到的消息类型进行不同的处理。 -例如,如果你发送一个 `'content-changed'` 的消息,页面将会重新加载。 +例如,如果你发送一个 `'static-changed'` 的消息,页面将会重新加载。 ```js export default { @@ -66,7 +66,7 @@ export default { setupMiddlewares: [ (middlewares, server) => { if (someCondition) { - server.sockWrite('content-changed'); + server.sockWrite('static-changed'); } }, ], @@ -74,6 +74,8 @@ export default { }; ``` +> 发送 `content-changed` 与 `static-changed` 具有相同的效果。由于 `content-changed` 已经被弃用,请优先使用 `static-changed`。 + ### environments `environments` 包含 Rsbuild 的 [environment API](/api/javascript-api/environment-api#environment-api),这允许你在服务端获取特定环境下的构建产物信息。