Repository navigation
perf(pages): lazy-load documentation content by language - #1992
Conversation
Split the docs content index into a lightweight directory (slug order, language availability, cached loader) plus five per-language content bundles behind explicit import() boundaries. The docs page and full-text search read the same loaded language content, English fallback loads only when a partial locale needs it, failed loads stay retryable, and stale responses are ignored after a language switch.
|
🔍 OpenCodeReview found 4 issue(s) in this PR.
📄
|
| zh: DOC_SLUG_ORDER, | ||
| ja: DOC_SLUG_ORDER, | ||
| ko: DOC_SLUG_ORDER, | ||
| ru: DOC_SLUG_ORDER, |
There was a problem hiding this comment.
Misleading partial-locale setup for Russian: The comment in ru.ts states "Russian is an incremental locale: entries missing here fall back to English," and the availableTranslations / isPartialLocale infrastructure exists to support partial locales. However, ru is currently mapped to the full DOC_SLUG_ORDER, so isPartialLocale('ru') returns false and hasTranslation() returns true for every slug.
This is technically correct today (all 19 Russian .md files exist), but the comment/code mismatch is confusing. If a future maintainer removes a Russian translation expecting the fallback mechanism to kick in, they also need to remember to remove the slug from availableTranslations.ru — otherwise hasTranslation will lie and the page won't load the English fallback.
Either update the ru.ts comment to reflect that Russian is currently complete, or add a test/assertion that validates availableTranslations stays consistent with what each bundle actually exports.
| | 'faq' | ||
| | 'chatgpt-preview'; | ||
|
|
||
| export type LocalizedDocs = Partial<Record<DocSlug, string>>; |
There was a problem hiding this comment.
Type safety gap: LocalizedDocs is defined as Partial<Record<DocSlug, string>>, which makes every slug optional. This means TypeScript will not flag a missing key in any language bundle — including English, which should always be complete. If a contributor accidentally removes or misspells a key in en.ts, the build succeeds and rawFor() silently returns '' at runtime.
Consider introducing a stricter type for bundles that must be complete:
export type CompleteLocalizedDocs = Record<DocSlug, string>;Then use CompleteLocalizedDocs for en.ts (and other complete locales) while keeping LocalizedDocs (Partial) only for truly incremental locales and the LoadedDocContent.docs field. This gives you compile-time enforcement where it matters most.
| /* Best-effort fallback: the load stays retryable via the next trigger. */ | ||
| }); | ||
| return () => { cancelled = true; }; | ||
| }, [docState, activeSlug, searchQuery]); |
There was a problem hiding this comment.
Using the entire docState object as a dependency causes this effect to re-run on every state transition (e.g., loading→ready, ready→error, and even after the fallback's own setDocState call adds English). While the early-return guards prevent redundant fetches, each re-run still triggers cleanup and re-subscription.
Consider deriving more stable dependencies instead, e.g.:
const loadedLanguage = docState.status === 'ready' ? docState.content.language : null;
const hasEnglish = docState.status === 'ready' ? !!docState.content.english : false;Then depend on [loadedLanguage, hasEnglish, activeSlug, searchQuery]. This avoids re-triggering the effect when unrelated state transitions occur (e.g., going from loading to ready for the same language, or the fallback's own update adding english).
- type complete locales as Record<DocSlug, string> so a missing key fails at compile time; keep Partial only for incremental bundles - derive scalar dependencies for the English-fallback effect so unrelated docState transitions do not re-trigger it - render prev/next pagination only once content is ready - clarify the Russian bundle's maintenance contract with the availability directory
|
@wzxsdf Thanks for the language-level split. Pages CI is green (81 tests), and the build output confirms separate language chunks. Before merging, please address the following two medium-severity issues and complete the verification requested by #1895. 1. Search reports "no results" while its content is still loading or has failed
Opening search and typing during a cold language load therefore looks like a completed search with no matches; a failed download produces the same misleading state. Results do update on eventual success, but pending and failed searches need their own loading/error presentation and an actionable retry. Only show "no results" once all content required for that search is ready. 2. English fallback failures leave missing pages blank without a retry actionThe fallback catch ignores the rejection while All five shipped locales are currently complete, so this is not a claim that their existing translated pages fail. However, preserving partial-locale fallback is an explicit requirement of #1895. Please track fallback loading/error state and expose a retry for the required English request, including when search needs it. Verification to complete before merge
Reviewed snapshot: AI-assisted review using OpenAI Codex and |
- the search modal reports loading and error states with a retry action while its content is pending or failed, and shows no results only once every required content has arrived - the English fallback loads through a tracked state machine, so a missing article or an active search in a partial locale surfaces loading, failure and retry states instead of a blank body or a silent catch - add regression tests for search content states, partial-locale fallback, and asynchronous navigation (fragment scroll, TOC, history back/forward, rapid language switches)
|
@lizhengfeng101 Thanks for the detailed review — both issues are addressed in bc9aed6, along with the four verification items. 1. Search reports loading/error states instead of premature "no results"
2. Fallback failures are tracked and retryableThe English fallback now runs through a tracked state machine ( VerificationTests — 92 passing (was 81):
Browser network evidence — production builds of
The PR build ships five independent language bundles (en 267 KB, zh 249 KB, ja 337 KB, ko 312 KB, ru 421 KB uncompressed); opening a page fetches only the selected language's bundle, and the other four are never requested — including after the page settles. Compressed transfer sizes are reported separately from the uncompressed asset sizes above. |
|
@wzxsdf Thanks for the follow-up. The previous two findings are addressed in Two medium-severity issues remain before merge: 1. P2: The new tests fail the required English-source check
The repository's unchanged English-source verifier was run read-only against this snapshot and exited 1, reporting exactly these seven lines. Since Please reference the existing translation-table values in these assertions, or add narrowly scoped 2. P2: Retry cannot recover an obsolete language chunk after deploymentThe main-language catch and English-fallback catch discard the error, while the retry handlers only rerun the same dynamic import. A concrete affected workflow is:
The existing route ErrorBoundary already provides guarded reload recovery for chunk-load errors, but the locally caught asynchronous failures bypass it. Previously, opening documentation loaded all languages, so this first-switch-after-deployment failure was not introduced by a separate language request. Please retain in-place retry for transient failures, as #1895 requires, while providing a guarded reload escape path for persistent/stale chunk failures, covering both the selected language and English fallback. An explicit, verified historical-asset retention policy is another possible solution; the current deployment workflow does not establish one. Add a regression case for an old runtime requesting an unavailable language chunk. This second finding is based on the loading/error paths and deployment configuration; a real cross-deployment browser reproduction was not performed during this review. Verification before merge
The language-level split remains appropriate. First-use language switching needing a network connection is an intentional consequence of lazy loading, not a request to prefetch all languages or expand this PR into per-article splitting. The reported Network measurements were not independently rerun in this review. Reviewed snapshot: AI/LLM disclosure: this follow-up review used OpenAI Codex and |
Keep transient language and fallback failures retryable in place, then expose the guarded page reload recovery path when the same chunk failure persists across a retry. Share chunk classification and reload handling with ErrorBoundary, and cover stale chunk recovery for main and fallback content. Use translation-table values in localized test assertions so the required English-source check remains clean.
|
@lizhengfeng101 The two remaining P2 items are addressed in English-source check
Persistent stale-chunk recovery
New regression coverage
Current-head verification
The cold-cache browser measurements remain consistent with the earlier evidence: with a real Chrome profile and production builds, English fetched only the English docs chunk (91.1 KB wire) and Chinese fetched only the Chinese docs chunk (94.8 KB wire); the other language chunks were not requested, and there were zero requests after the 5-second settle window. |
|
Thanks for the work on this PR, @wzxsdf. It has been merged, and we are tracking the two remaining partial-locale cases separately in #1994: stale English-fallback error state after switching languages, and internal fragment navigation when fallback content loads asynchronously. Please verify both scenarios against current I tried assigning #1994 to you, but GitHub did not accept the assignment. Could you leave a comment on #1994 to acknowledge the follow-up? We can then retry the assignment. AI assistance: this message was drafted with OpenAI Codex; the model identifier is not available in the conversation record. Posting was explicitly requested by the maintainer. |
|
@lizhengfeng101 text |
Description
Split documentation content by language so opening a docs page downloads only the selected language's bundle instead of all five.
Fixes #1895
Implementation
pages/src/content/docs/index.tsno longer imports any Markdown body. It holds the canonical slug order, per-language availability, and a cached on-demand loader, so importing it stays lightweight.en/zh/ja/ko/ru.tseach import their language's Markdown behind an explicitimport()boundary, so webpack emits five independent chunks.loadLanguageContentshares in-flight requests, caches successful loads for the session, and evicts failed loads so they stay retryable.DocsPageand the full-text search read the sameLoadedDocContent. The search hook contract is unchanged, so blog search is unaffected. English fallback loads only when the active page or an active search in a partial locale needs it — never speculatively; a transient download failure is never treated as a missing translation.Behavior details:
vitest.config.tsgains a raw-source transform for.mdthat mirrors webpack'sasset/sourcerule, so tests import the real content files.Verification
npm run lintandnpm run typecheckare clean (two pre-existing warnings inMarkdownRenderer.tsxuntouched).npm test: 81/81 — 65 existing tests plus 16 new ones covering loader caching/in-flight sharing/retry, directory-vs-bundle consistency, search order and English fallback, and page loading/race/retry behavior.npm run build: five per-language async chunks (en 249 KiB, ja 337 KiB, ko 312 KiB, zh, ru 421 KiB); no Markdown body remains in the entry or route chunks.npm run size: 97.12 kB against the 150 kB limit.AI/LLM Disclosure
This pull request was prepared with AI assistance: code inspection, implementation, and test preparation were done with the ZCode agent (GLM model). I reviewed and understand every change in this PR.