Skip to content

fix(plugin-client-redirects): redirect before hydration - #3555

Open
SoonIter wants to merge 1 commit into
mainfrom
fix/client-redirect-before-hydration
Open

fix(plugin-client-redirects): redirect before hydration#3555
SoonIter wants to merge 1 commit into
mainfrom
fix/client-redirect-before-hydration

Conversation

@SoonIter

@SoonIter SoonIter commented Jul 27, 2026

Copy link
Copy Markdown
Member

Summary

This PR runs initial client redirects from a production-only inline head script so they happen before hydration without flashing the source page.

It also keeps the production runtime redirect component for SPA navigation and as a fallback when a strict CSP blocks inline scripts. The inline path now handles base correctly, is isolated in an IIFE, and coordinates with the built-in locale redirect to avoid competing navigations. The English and Chinese docs describe the production-only behavior and server-redirect recommendation.

Related PR

Checklist

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

Copilot AI review requested due to automatic review settings July 27, 2026 10:59

@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: 5acfdde4c3

ℹ️ 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/plugin-client-redirects/src/index.ts
Comment thread packages/plugin-client-redirects/src/inlineRedirect.ts Outdated
@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 3 projects with changes.

📊 Quick Summary
Project Total Size Gzip Size Change Gzip Change
website_js 16.8 MB 2.9 MB +136.0 B (0.0%) +5.0 B (0.0%)
website_html 14.1 MB 2.0 MB +18.1 KB (0.1%) +7.3 KB (0.4%)
website_md 1.8 MB 260.3 KB -6.0 B (-0.0%) -3.0 B (-0.0%)
auto_nav_sidebar_js 524.5 KB 164.3 KB 0 0
auto_nav_sidebar_html 304.9 KB 60.7 KB 0 0
📋 Detailed Reports (Click to expand)

📁 website_js

Path: website/doc_build/diff-rsdoctor/website_js/rsdoctor-data.json

📌 Baseline Commit: 5abfd4c8b8 | PR: #3561

Metric Current Baseline Change
📊 Total Size 16.8 MB 16.8 MB +136.0 B (0.0%)
🗜️ Gzip Size 2.9 MB 2.9 MB +5.0 B (0.0%)
📄 JavaScript 16.5 MB 16.5 MB +136.0 B (0.0%)
🎨 CSS 139.0 KB 139.0 KB 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 172.1 KB 172.1 KB 0

📦 Download Diff Report: website_js Bundle Diff

📁 website_html

Path: website/doc_build/diff-rsdoctor/website_html/rsdoctor-data.json

📌 Baseline Commit: 5abfd4c8b8 | PR: #3561

Metric Current Baseline Change
📊 Total Size 14.1 MB 14.1 MB +18.1 KB (0.1%)
🗜️ Gzip Size 2.0 MB 2.0 MB +7.3 KB (0.4%)
📄 JavaScript 0 B 0 B 0
🎨 CSS 0 B 0 B 0
🌐 HTML 14.1 MB 14.1 MB +18.1 KB (0.1%)
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: website_html Bundle Diff

📁 website_md

Path: website/doc_build/diff-rsdoctor/website_md/rsdoctor-data.json

📌 Baseline Commit: 5abfd4c8b8 | PR: #3561

Metric Current Baseline Change
📊 Total Size 1.8 MB 1.8 MB -6.0 B (-0.0%)
🗜️ Gzip Size 260.3 KB 260.3 KB -3.0 B (-0.0%)
📄 JavaScript 0 B 0 B 0
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 1.8 MB 1.8 MB -6.0 B (-0.0%)

📦 Download Diff Report: website_md Bundle Diff

Generated by Rsdoctor GitHub Action

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates @rspress/plugin-client-redirects to perform redirects via a production-only inline <script> injected into the HTML head so redirects can happen before React hydration (reducing the visible “flash” of the source page). It removes the previous runtime React component implementation, trims React-related dependencies, and updates docs/tests to reflect the new production-only behavior.

Changes:

  • Replace the runtime Redirect.tsx global UI component with a generated inline head script (production only).
  • Add unit tests for the inline script generator and update e2e coverage to validate production behavior and dev inactivity.
  • Update English/Chinese docs to clearly state the plugin is production-only and depends on build output.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
website/docs/zh/plugin/official-plugins/client-redirects.mdx Clarifies production-only behavior and guidance for redirects (ZH).
website/docs/en/plugin/official-plugins/client-redirects.mdx Clarifies production-only behavior and guidance for redirects (EN).
pnpm-lock.yaml Removes React-related dependencies from the plugin’s dependency graph.
packages/plugin-client-redirects/tests/inlineRedirect.test.ts Adds unit tests for inline redirect script generation and prod-only injection.
packages/plugin-client-redirects/static/Redirect.tsx Removes the previous React runtime redirect component implementation.
packages/plugin-client-redirects/src/inlineRedirect.ts Introduces inline redirect script generator used for head injection.
packages/plugin-client-redirects/src/index.ts Switches plugin behavior to inject inline head script only in production.
packages/plugin-client-redirects/package.json Drops static/ from published files and removes React-related devDependencies.
e2e/fixtures/client-redirects/index.test.ts Updates e2e to validate production redirects via preview build and adds dev inactivity test.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/plugin-client-redirects/src/index.ts Outdated
Comment thread packages/plugin-client-redirects/src/inlineRedirect.ts Outdated
@SoonIter
SoonIter force-pushed the fix/client-redirect-before-hydration branch from 5acfdde to f09905d Compare July 27, 2026 11:08

@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: f09905da4f

ℹ️ 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/plugin-client-redirects/src/index.ts
@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

Deploying rspress-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: c1a7d24
Status: ✅  Deploy successful!
Preview URL: https://c1512d27.rspress-v2.pages.dev
Branch Preview URL: https://fix-client-redirect-before-h.rspress-v2.pages.dev

View logs

@SoonIter
SoonIter force-pushed the fix/client-redirect-before-hydration branch from f09905d to c1a7d24 Compare July 29, 2026 09: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.

2 participants