fix(server): ensure historyApiFallback takes precedence over html falback#6520
fix(server): ensure historyApiFallback takes precedence over html falback#6520chenjiahan merged 2 commits intomainfrom
Conversation
✅ Deploy Preview for rsbuild ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
💡 Codex Review
rsbuild/packages/core/src/server/prodServer.ts
Lines 121 to 131 in 79f061e
The dev middleware now queues historyApiFallbackMiddleware ahead of the HTML fallback so custom rewrites run before the default index fallback, but startProdServer continues to register the static asset middleware (with single: htmlFallback === 'index') before historyApiFallbackMiddleware. When htmlFallback is left at its default 'index', the sirv middleware serves /index.html for unknown routes and the request never reaches the history middleware, so rewrites such as { from: /^\/baz/, to: '/foo.html' } still cannot work in preview/production. The same fix needs to be applied here; otherwise the feature only works in dev mode.
ℹ️ 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".
There was a problem hiding this comment.
Pull Request Overview
This PR reorders the dev server middleware stack to ensure that historyApiFallback takes precedence over the default htmlFallback middleware. The key change moves the htmlFallback middleware registration to occur after the historyApiFallback middleware, allowing history API rewrites to be processed first.
- Reordered middleware in
devMiddlewares.tssohistoryApiFallbackexecutes beforehtmlFallback - Added comprehensive test coverage for both basic history API fallback and the rewrites feature
- Added clear documentation comment explaining the precedence relationship
Reviewed Changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/server/devMiddlewares.ts | Moved htmlFallback middleware registration after historyApiFallback to ensure correct precedence order |
| e2e/cases/server/history-api-fallback/index.test.ts | Added tests for basic history API fallback functionality in both dev and preview servers |
| e2e/cases/server/history-api-fallback-rewrites/index.test.ts | Added test for historyApiFallback.rewrites configuration |
| e2e/cases/server/history-api-fallback-rewrites/rsbuild.config.ts | Configuration for rewrites test with multiple entry points |
| e2e/cases/server/history-api-fallback-rewrites/src/index.js | Source file for index entry point |
| e2e/cases/server/history-api-fallback-rewrites/src/foo.js | Source file for foo entry point |
| e2e/cases/server/history-api-fallback-rewrites/src/bar.js | Source file for bar entry point |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Summary
Make
historyApiFallbackmiddleware execute beforehtmlFallbackmiddleware to properly handle rewrites and fallback routes.When users explicitly configure
historyApiFallback.rewrites, it should take precedence and apply automatically without requiring manual disabling ofhtmlFallback.Checklist