Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: prefer to use static-changed socket type #4273

Merged
merged 1 commit into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading