Skip to content

perf: skip the switch-locale-path html scan without a link - #4173

Open
onmax wants to merge 1 commit into
nuxt-modules:mainfrom
onmax:perf/skip-slp-html-scan
Open

onmax wants to merge 1 commit into
nuxt-modules:mainfrom
onmax:perf/skip-slp-html-scan

Conversation

@onmax

@onmax onmax commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🔗 Linked issue

No issue. I found this while profiling SSR requests.

Repro with a before and after: https://github.com/onmax/repros/tree/repro/i18n-slp-html-scan/i18n-slp-html-scan (node verify.mjs && node bench.mjs)

📚 Description

switch-locale-path-ssr runs a regex over the whole rendered HTML in app:rendered, on every request. Most pages have no SwitchLocalePathLink, but they still pay for the scan. Vue SSR output has a lot of <!--[--> comments, and each one starts a partial match.

With this change, SwitchLocalePathLink marks its SSR context during setup. The plugin skips the scan when the render has no mark. Pages with the link work as before.

From the repro: a 521 KB page made of 2000 two-root components, Nuxt 4.6.2, i18n 10.6.0, production build. Median of 6 alternating rounds of 2000 requests:

before after
HTML scans, 5 requests 5 0
regex time per request 0.191 ms 0
page with the link 1 scan, href rewritten 1 scan, href rewritten

@github-actions

Copy link
Copy Markdown

We've flagged this as a potential contribution without a human behind it. We welcome the thoughtful use of AI tools when contributing to Nuxt i18n, but ask all contributors to follow two core principles:

  1. Never let an LLM speak for you - all comments, issues, and PR descriptions should be written in your own words, reflecting your own understanding.
  2. Never let an LLM think for you - only submit contributions you fully understand and can explain.

Please review our AI-assisted contribution guidelines and update this contribution if needed.

If this was flagged in error, we apologise! 😳 Just let us know. 🙏

@coderabbitai

coderabbitai Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: adff70ac-6d27-445d-b13a-dec277615e8f
Commits

Reviewing files that changed from the base of the PR and between 8158ed8 and b239de0.

Files selected for processing: 3
  • src/runtime/components/SwitchLocalePathLink.ts
  • src/runtime/plugins/switch-locale-path-ssr.ts
  • src/runtime/shared/switch-locale-path.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Walkthrough

During server rendering, SwitchLocalePathLinkWrapper marks the Nuxt SSR context when it renders. The SSR locale-path plugin checks whether the context is marked and returns when the HTML is absent or no switch-locale-path link was marked. Otherwise, it continues through the existing replacement logic. The shared module stores marked contexts in a WeakSet.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: Minimal · up to b239d

The optimization safely skips unnecessary scans while preserving rendered locale links.

Pre-merge checks: Passed 4 · Failed 1

Failed 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: skipping the switch-locale-path HTML scan when no link exists.
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 unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

This branch has not been deployed

No deployments
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