Skip to content

fix(server): ensure historyApiFallback takes precedence over html falback#6520

Merged
chenjiahan merged 2 commits intomainfrom
history_api_fallback_rewrites_1106
Nov 6, 2025
Merged

fix(server): ensure historyApiFallback takes precedence over html falback#6520
chenjiahan merged 2 commits intomainfrom
history_api_fallback_rewrites_1106

Conversation

@chenjiahan
Copy link
Member

Summary

Make historyApiFallback middleware execute before htmlFallback middleware to properly handle rewrites and fallback routes.

When users explicitly configure historyApiFallback.rewrites, it should take precedence and apply automatically without requiring manual disabling of htmlFallback.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings November 6, 2025 15:31
@netlify
Copy link

netlify bot commented Nov 6, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 085029f
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/690cbfd4b97aea00085a27d4
😎 Deploy Preview https://deploy-preview-6520--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 75 (🟢 up 2 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

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

Choose a reason for hiding this comment

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

💡 Codex Review

this.applyStaticAssetMiddleware();
if (historyApiFallback) {
this.middlewares.use(
historyApiFallbackMiddleware(
historyApiFallback === true ? {} : historyApiFallback,
),
);
// ensure fallback request can be handled by sirv
this.applyStaticAssetMiddleware();

P1 Badge Preview server still intercepts history rewrites before middleware

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".

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.ts so historyApiFallback executes before htmlFallback
  • 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.

@chenjiahan chenjiahan merged commit fb0f6a7 into main Nov 6, 2025
11 checks passed
@chenjiahan chenjiahan deleted the history_api_fallback_rewrites_1106 branch November 6, 2025 15:47
@chenjiahan chenjiahan mentioned this pull request Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments