Skip to content

feat(core): watch loaded config files for restart#8149

Merged
chenjiahan merged 2 commits into
mainfrom
chenjiahan/watch-loaded-config-files
Jul 20, 2026
Merged

feat(core): watch loaded config files for restart#8149
chenjiahan merged 2 commits into
mainfrom
chenjiahan/watch-loaded-config-files

Conversation

@chenjiahan

Copy link
Copy Markdown
Member

Summary

This PR lets JavaScript API users automatically watch loaded configuration files and their imported dependencies for restart requests. It moves config file watching from the CLI into Core and adds focused end-to-end coverage and documentation for the CLI and JavaScript API behavior.

Related Links

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Configuration file and dependency watching is now derived by restart handling from the loaded configuration context instead of being registered during CLI config loading. An end-to-end test verifies that changing an imported configuration dependency emits a dev-server restart event. English and Chinese documentation describe configuration watching, restart behavior, and the JavaScript API requirements.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: watching loaded config files for restart.
Description check ✅ Passed The description accurately summarizes the core change, docs, and end-to-end coverage added in this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 20, 2026

Copy link
Copy Markdown

Deploying rsbuild with  Cloudflare Pages  Cloudflare Pages

Latest commit: 16bd939
Status: ✅  Deploy successful!
Preview URL: https://b62eebcb.rsbuild-v2.pages.dev
Branch Preview URL: https://chenjiahan-watch-loaded-conf.rsbuild-v2.pages.dev

View logs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
e2e/cases/javascript-api/restart-config-files/index.test.ts (1)

32-40: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Writing to a file repeatedly during polling can cause excessive disk I/O and watcher events.

Because expect.poll evaluates the callback frequently (often every ~100ms), writing to configDependency on every iteration until restartContext is set can trigger many file system events. This might queue multiple restart requests and cause flaky test behavior or excessive disk I/O.

Consider writing the file once after a brief delay, or using a less aggressive retry mechanism to trigger the watcher.

♻️ Proposed refactor (delay before write)
-  try {
-    await expect
-      .poll(
-        () => {
-          if (!restartContext) {
-            fs.writeFileSync(configDependency, `${originalConfig}\n// ${++version}\n`);
-          }
-          return restartContext;
-        },
-        { timeout: 5_000 },
-      )
-      .toEqual({
-        action: 'dev',
-        filePath: configDependency,
-      });
-  } finally {
+  try {
+    // Wait for watchers to initialize in the background, then trigger change
+    setTimeout(() => {
+      fs.writeFileSync(configDependency, `${originalConfig}\n// updated\n`);
+    }, 500);
+
+    await expect
+      .poll(() => restartContext, { timeout: 5_000 })
+      .toEqual({
+        action: 'dev',
+        filePath: configDependency,
+      });
+  } finally {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@e2e/cases/javascript-api/restart-config-files/index.test.ts` around lines 32
- 40, Update the expect.poll callback around restartContext so it does not
rewrite configDependency on every polling iteration; trigger the configuration
change once after a brief delay or otherwise guard the write to prevent repeated
filesystem events, while preserving the existing restartContext polling
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@e2e/cases/javascript-api/restart-config-files/index.test.ts`:
- Around line 32-40: Update the expect.poll callback around restartContext so it
does not rewrite configDependency on every polling iteration; trigger the
configuration change once after a brief delay or otherwise guard the write to
prevent repeated filesystem events, while preserving the existing restartContext
polling behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 88de1bdf-99f5-427a-b574-002e38a23885

📥 Commits

Reviewing files that changed from the base of the PR and between 13f55c4 and dc5bfdb.

📒 Files selected for processing (12)
  • e2e/cases/javascript-api/restart-config-files/index.test.ts
  • e2e/cases/javascript-api/restart-config-files/rsbuild.config.mjs
  • e2e/cases/javascript-api/restart-config-files/sharedConfig.mjs
  • e2e/cases/javascript-api/restart-config-files/src/index.js
  • packages/core/src/cli/init.ts
  • packages/core/src/restart.ts
  • website/docs/en/api/javascript-api/core.mdx
  • website/docs/en/config/dev/watch-files.mdx
  • website/docs/en/guide/configuration/rsbuild.mdx
  • website/docs/zh/api/javascript-api/core.mdx
  • website/docs/zh/config/dev/watch-files.mdx
  • website/docs/zh/guide/configuration/rsbuild.mdx

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 16bd9391d3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/restart.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
e2e/cases/javascript-api/dev-server-restart/index.test.ts (1)

41-49: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Throttle rapid file writes inside the polling loop.

Writing to the configuration file repeatedly inside expect.poll without throttling can cause the file to be updated very rapidly (e.g., every 50ms, depending on the test runner). This risks triggering multiple concurrent dev server restarts, which may lead to test flakiness, resource leaks, or EADDRINUSE errors if the server attempts to restart in the background.

Consider increasing the polling interval (e.g., using { interval: 500 } or { intervals: [500] } depending on the test framework configuration) to give the server enough time to process the initial file change and emit the restart event before writing again.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@e2e/cases/javascript-api/dev-server-restart/index.test.ts` around lines 41 -
49, Throttle the expect.poll loop that writes configDep by configuring a polling
interval of about 500ms, while preserving the existing restartContext check and
expected result. Use the polling options supported by the test framework so
repeated writes allow the dev server to process each restart.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@e2e/cases/javascript-api/dev-server-restart/index.test.ts`:
- Around line 41-49: Throttle the expect.poll loop that writes configDep by
configuring a polling interval of about 500ms, while preserving the existing
restartContext check and expected result. Use the polling options supported by
the test framework so repeated writes allow the dev server to process each
restart.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5d94da1e-fb0c-46dc-acd4-4d366ba4222f

📥 Commits

Reviewing files that changed from the base of the PR and between dc5bfdb and 16bd939.

📒 Files selected for processing (7)
  • e2e/cases/javascript-api/dev-server-restart/index.test.ts
  • e2e/cases/javascript-api/dev-server-restart/rsbuild.config.mjs
  • e2e/cases/javascript-api/dev-server-restart/src/index.js
  • website/docs/en/api/javascript-api/core.mdx
  • website/docs/en/config/dev/watch-files.mdx
  • website/docs/zh/api/javascript-api/core.mdx
  • website/docs/zh/config/dev/watch-files.mdx
🚧 Files skipped from review as they are similar to previous changes (2)
  • website/docs/en/api/javascript-api/core.mdx
  • website/docs/zh/api/javascript-api/core.mdx

@chenjiahan
chenjiahan merged commit 78fa082 into main Jul 20, 2026
8 checks passed
@chenjiahan
chenjiahan deleted the chenjiahan/watch-loaded-config-files branch July 20, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant