Skip to content

Commit

Permalink
chore: prefer to use static-changed socket type (#4273)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Dec 25, 2024
1 parent 6446f6c commit df5564d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion e2e/cases/server/setup-middlewares/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('setupMiddlewares', async ({ page }) => {
i++;
next();
});
reloadFn = () => server.sockWrite('content-changed');
reloadFn = () => server.sockWrite('static-changed');
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/server/compilerDevMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/server/socketServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export class SocketServer {

if (shouldReload) {
return this.sockWrite({
type: 'content-changed',
type: 'static-changed',
compilationId,
});
}
Expand Down
6 changes: 4 additions & 2 deletions website/docs/en/config/dev/setup-middlewares.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,24 @@ 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 {
dev: {
setupMiddlewares: [
(middlewares, server) => {
if (someCondition) {
server.sockWrite('content-changed');
server.sockWrite('static-changed');
}
},
],
},
};
```

> 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.
Expand Down
6 changes: 4 additions & 2 deletions website/docs/zh/config/dev/setup-middlewares.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,24 @@ export default {

`sockWrite` 允许中间件向 HMR 客户端传递一些消息,HMR 客户端将根据接收到的消息类型进行不同的处理。

例如,如果你发送一个 `'content-changed'` 的消息,页面将会重新加载。
例如,如果你发送一个 `'static-changed'` 的消息,页面将会重新加载。

```js
export default {
dev: {
setupMiddlewares: [
(middlewares, server) => {
if (someCondition) {
server.sockWrite('content-changed');
server.sockWrite('static-changed');
}
},
],
},
};
```

> 发送 `content-changed``static-changed` 具有相同的效果。由于 `content-changed` 已经被弃用,请优先使用 `static-changed`
### environments

`environments` 包含 Rsbuild 的 [environment API](/api/javascript-api/environment-api#environment-api),这允许你在服务端获取特定环境下的构建产物信息。
Expand Down

0 comments on commit df5564d

Please sign in to comment.