Repository navigation
fix(pages): recover partial-locale fallback and fragment navigation - #2000
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.
- 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
- 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)
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.
|
@wzxsdf merge conflicts |
|
🔍 OpenCodeReview found 3 issue(s) in this PR.
|
| setEnglishFallback({ status: 'loading', requestKey: key }); | ||
| loadLanguageContent('en') | ||
| .then(docs => { | ||
| setEnglishFallback({ status: 'ready', docs }); | ||
| }) | ||
| .catch(error => { | ||
| setEnglishFallback({ status: 'error', requestKey: key, error, attempt }); | ||
| }); |
There was a problem hiding this comment.
Bug: This effect lacks a cleanup/cancellation mechanism, unlike the main language loading effect above which correctly uses a cancelled flag. If dependencies change (e.g., user navigates to a different slug or triggers a retry) while loadLanguageContent('en') is still in flight, the stale .then() / .catch() callbacks will still execute and call setEnglishFallback. This could overwrite newer state — for example, a failed load resolving after a subsequent successful load has already set the state to 'ready', incorrectly flipping it back to 'error'.
Add a cancellation guard consistent with the main language effect:
Suggestion:
| setEnglishFallback({ status: 'loading', requestKey: key }); | |
| loadLanguageContent('en') | |
| .then(docs => { | |
| setEnglishFallback({ status: 'ready', docs }); | |
| }) | |
| .catch(error => { | |
| setEnglishFallback({ status: 'error', requestKey: key, error, attempt }); | |
| }); | |
| let cancelled = false; | |
| setEnglishFallback({ status: 'loading', requestKey: key }); | |
| loadLanguageContent('en') | |
| .then(docs => { | |
| if (!cancelled) setEnglishFallback({ status: 'ready', docs }); | |
| }) | |
| .catch(error => { | |
| if (!cancelled) setEnglishFallback({ status: 'error', requestKey: key, error, attempt }); | |
| }); | |
| return () => { cancelled = true; }; |
| const pageStatus: 'loading' | 'error' | 'ready' = | ||
| docState.status !== 'ready' | ||
| ? docState.status | ||
| : pageNeedsFallback && englishFallback.status !== 'ready' | ||
| ? (englishFallback.status === 'error' ? 'error' : 'loading') | ||
| : 'ready'; |
There was a problem hiding this comment.
Nested ternary expressions (3 levels deep) reduce readability and violate the no-nested-ternary guideline. Consider extracting this into a helper function or using if/else logic for clarity.
Suggestion:
| const pageStatus: 'loading' | 'error' | 'ready' = | |
| docState.status !== 'ready' | |
| ? docState.status | |
| : pageNeedsFallback && englishFallback.status !== 'ready' | |
| ? (englishFallback.status === 'error' ? 'error' : 'loading') | |
| : 'ready'; | |
| let pageStatus: 'loading' | 'error' | 'ready'; | |
| if (docState.status !== 'ready') { | |
| pageStatus = docState.status; | |
| } else if (pageNeedsFallback && englishFallback.status !== 'ready') { | |
| pageStatus = englishFallback.status === 'error' ? 'error' : 'loading'; | |
| } else { | |
| pageStatus = 'ready'; | |
| } |
| const searchContentStatus: 'loading' | 'error' | 'ready' = | ||
| docState.status === 'loading' | ||
| ? 'loading' | ||
| : docState.status === 'error' | ||
| ? 'error' | ||
| : searchNeedsEnglish && englishFallback.status !== 'ready' | ||
| ? (englishFallback.status === 'error' ? 'error' : 'loading') | ||
| : 'ready'; |
There was a problem hiding this comment.
Same nested ternary issue as pageStatus above — 3 levels of nesting. Extract to a helper or use if/else for consistency and readability.
Suggestion:
| const searchContentStatus: 'loading' | 'error' | 'ready' = | |
| docState.status === 'loading' | |
| ? 'loading' | |
| : docState.status === 'error' | |
| ? 'error' | |
| : searchNeedsEnglish && englishFallback.status !== 'ready' | |
| ? (englishFallback.status === 'error' ? 'error' : 'loading') | |
| : 'ready'; | |
| let searchContentStatus: 'loading' | 'error' | 'ready'; | |
| if (docState.status === 'loading') { | |
| searchContentStatus = 'loading'; | |
| } else if (docState.status === 'error') { | |
| searchContentStatus = 'error'; | |
| } else if (searchNeedsEnglish && englishFallback.status !== 'ready') { | |
| searchContentStatus = englishFallback.status === 'error' ? 'error' : 'loading'; | |
| } else { | |
| searchContentStatus = 'ready'; | |
| } |
|
@lizhengfeng101
|
|
@wzxsdf Thanks for the update. I checked An in-flight English fallback can leave search or the article stuck on “Loading” with no Retry button. Two ways to reach it with the partial-locale fixture:
Could you keep the shared English request able to publish its result while the component is mounted, or reattach to it when demand returns? The production loader already shares one promise per language. The new navigation test instead resolves two independent English promises with different contents. Please model one delayed English bundle and assert the visible outcome in both sequences: the latest query gets its results, the returning article gets its body, and a rejected request exposes Retry rather than leaving the spinner. For #1994, the remaining fragment check is that a failed load followed by a successful Retry still scrolls to the original heading. Review basis: static tracing of this commit with OpenAI Codex and |
Qiyuanqiii
left a comment
There was a problem hiding this comment.
Thanks for the additional regression tests. The shared fallback request handling looks much better now.
One acceptance scenario from #1994 still appears to be missing dedicated test coverage:
- Start in a partial locale (
zh) on an untranslated article (installation). - Reject the initial English fallback request.
- Switch to
enand successfully load the English content. - Switch back to
zhon the same article. - Verify that the cached English content renders immediately, without clicking Retry or initiating another English load.
The current implementation appears to handle this correctly by reconciling successful primary English loads with the shared fallback state.
Could you add a regression test for this exact sequence? Since it is the first acceptance criterion of #1994, covering the complete language-switch round trip would help prevent future regressions.
Thanks!
|
@Qiyuanqiii The test also verifies that the error and loading states are cleared. All 26 DocsPage tests and 105 Pages tests pass locally, along with typecheck, lint (no errors), make check, and make test. |
|
@lizhengfeng101 |
|
lizhengfeng’s review is not yet complete. We also need to consider the merge order and run corresponding benchmarks to ensure there is no extra performance regression, so kindly wait a few days, thanks. |
|
@wzxsdf Thanks for the follow-up. On
Could you keep the English subscription and retry count tied to the shared bundle rather than to the filter text? Please extend the rapid-input test to cover a trailing space followed by success and failure. For the retry case, please assert that editing alone does not start another load, and that editing during an explicit retry preserves Reload on a second chunk failure. Verification: AI-assisted review with OpenAI Codex and |
|
@lizhengfeng101 Thanks for catching both. Fixed in 2db42c7 by keying the fallback to the bundle itself:
Rapid-input coverage added: trailing-space edit mid-flight; query edit during a pending retry (Reload still offered after the second failure); clearing and re-entering the query reattaches the same in-flight bundle; article change during a pending retry (same Reload guarantee). 109/109 Pages tests, typecheck, lint, production build (97.64 kB brotli) pass. One deliberate behavior change: after a settled fallback failure, page navigation or query edits no longer auto re-fire the load (the old re-keying silently restarted it with a reset attempt). The failure now persists with Retry available, which is the retry-count-tied-to-the-bundle behavior requested. |
Summary
Fix the two partial-locale documentation issues tracked in #1994:
Closes #1994.
Changes
Reproduction
Both scenarios were reproduced against the merged lazy-loading implementation using the existing partial-locale test fixture:
../installation/#intro, while the destination article required delayed English fallback content.Testing
DocsPagetests: 21/21 passednpm --prefix pages run typechecknpm --prefix pages run lint— 0 errors; two existing Hook warnings remainnpm --prefix pages run size— 97.25 kB brotlied, below the 150 kB limitmake checkmake testgit diff --check