Skip to content

fix(pages): recover partial-locale fallback and fragment navigation - #2000

Merged
lizhengfeng101 merged 10 commits into
alibaba:mainfrom
wzxsdf:issue-1994-partial-locale-fixes
Nov 20, 2026
Merged

lizhengfeng101 merged 10 commits into
alibaba:mainfrom
wzxsdf:issue-1994-partial-locale-fixes

Conversation

@wzxsdf

@wzxsdf wzxsdf commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix the two partial-locale documentation issues tracked in #1994:

  • A stale English fallback error could remain after switching to English, successfully loading the English bundle, and switching back.
  • Internal documentation links with fragments could lose the hash, preventing navigation to headings after delayed fallback content loaded.

Closes #1994.

Changes

  • Reconcile successful English primary loads with the shared English fallback state.
  • Clear stale fallback attempt keys when English is active or successfully loaded.
  • Preserve fragments in internal documentation navigation.
  • Let the existing URL and content-ready effect perform fragment scrolling after delayed content renders.
  • Add regression coverage for fallback recovery, delayed fragment navigation, and browser back/forward history.

Reproduction

Both scenarios were reproduced against the merged lazy-loading implementation using the existing partial-locale test fixture:

  1. The first English fallback request was rejected, then English was loaded successfully and the page was switched back to the partial locale.
  2. A translated article linked to ../installation/#intro, while the destination article required delayed English fallback content.

Testing

  • DocsPage tests: 21/21 passed
  • Pages test suite: 99/99 passed
  • npm --prefix pages run typecheck
  • npm --prefix pages run lint — 0 errors; two existing Hook warnings remain
  • Production webpack build
  • npm --prefix pages run size — 97.25 kB brotlied, below the 150 kB limit
  • Docker make check
  • Docker make test
  • git diff --check

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.
@lizhengfeng101

Copy link
Copy Markdown
Contributor

@wzxsdf merge conflicts

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 3 issue(s) in this PR.

  • ✅ Successfully posted inline: 3 comment(s)

Comment thread pages/src/pages/DocsPage.tsx Outdated
Comment on lines +260 to +267
setEnglishFallback({ status: 'loading', requestKey: key });
loadLanguageContent('en')
.then(docs => {
setEnglishFallback({ status: 'ready', docs });
})
.catch(error => {
setEnglishFallback({ status: 'error', requestKey: key, error, attempt });
});

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.

bug · medium
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:

Suggested change
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; };

Comment thread pages/src/pages/DocsPage.tsx Outdated
Comment on lines +276 to +281
const pageStatus: 'loading' | 'error' | 'ready' =
docState.status !== 'ready'
? docState.status
: pageNeedsFallback && englishFallback.status !== 'ready'
? (englishFallback.status === 'error' ? 'error' : 'loading')
: 'ready';

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.

maintainability · medium
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:

Suggested change
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';
}

Comment thread pages/src/pages/DocsPage.tsx Outdated
Comment on lines +303 to +310
const searchContentStatus: 'loading' | 'error' | 'ready' =
docState.status === 'loading'
? 'loading'
: docState.status === 'error'
? 'error'
: searchNeedsEnglish && englishFallback.status !== 'ready'
? (englishFallback.status === 'error' ? 'error' : 'loading')
: 'ready';

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.

maintainability · medium
Same nested ternary issue as pageStatus above — 3 levels of nesting. Extract to a helper or use if/else for consistency and readability.

Suggestion:

Suggested change
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';
}

@wzxsdf

wzxsdf commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@lizhengfeng101
The requested fixes are complete and have been pushed in commit e03d9e1.
I addressed all three bot findings:

  • Added cancellation guards for stale English fallback requests.
  • Replaced the nested ternary used for pageStatus.
  • Replaced the nested ternary used for searchContentStatus.
  • Added regression coverage to ensure stale fallback responses cannot overwrite newer article content.
    All relevant checks pass, including 22/22 DocsPage tests, 101/101 Pages tests, typecheck, lint with no errors, production build, and bundle size validation.
    The PR is ready for review. Thanks!

@lizhengfeng101

Copy link
Copy Markdown
Contributor

@wzxsdf Thanks for the update. I checked e03d9e13: the English-language round trip now clears the old fallback error, and cross-article links retain their fragment. I found one regression in the new cancellation guard that should be fixed before merge.

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:

  • On a translated article, type a, then ab before the English bundle settles. The effect cleans up on every query change, but the request key only records whether the query is nonempty. Cleanup disables the original promise callbacks; the next effect sees the same key marked loading and returns. Neither success nor failure can reach the UI.
  • Open an untranslated article, navigate to a translated one while English is pending, then go back. Leaving clears the attempt key but leaves the fallback marked loading for the original article. Returning hits the same early return. Changing the dependency from the query string to a boolean would fix the typing case but not this one.

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 ocr, plus the passing Pages CI results; I did not run these sequences in a browser.

@Qiyuanqiii Qiyuanqiii 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.

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:

  1. Start in a partial locale (zh) on an untranslated article (installation).
  2. Reject the initial English fallback request.
  3. Switch to en and successfully load the English content.
  4. Switch back to zh on the same article.
  5. 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!

@wzxsdf

wzxsdf commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@Qiyuanqiii
Thanks for pointing this out. I’ve added a dedicated regression test for the exact zh → en → zh sequence: the initial English fallback fails, switching to English successfully loads the content, and switching back to Chinese renders the cached English article without clicking Retry or starting another English load.

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.

@Qiyuanqiii Qiyuanqiii 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.

LGTM

@wzxsdf

wzxsdf commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@lizhengfeng101
Thanks for the review rounds. All requested changes are in — the reattached shared English fallback, the zh → en → zh round-trip regression test, and the fragment-after-Retry coverage — and the latest checks are green. Could you merge this PR when convenient?

@Qiyuanqiii

Copy link
Copy Markdown
Contributor

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.

@lizhengfeng101

Copy link
Copy Markdown
Contributor

@wzxsdf Thanks for the follow-up. On 9d1e3de6, the language round trip and fragment-after-Retry now have coverage, and both ordinary typing and leaving an untranslated article and returning work with one English load. Two related search cases still need a fix before merge. Both use the partial-locale fixture from #1994.

  1. A trailing space can leave search stuck on “Loading.” On a translated article, type foo, press Space before the English bundle settles, then stop typing. On main (445ad9de), resolving the bundle reaches ready, and rejecting it reaches error with Retry. On this PR both outcomes stay loading. The effect cleans up on the raw query change, but the attempt key uses trim(). The old callback ignores the result, and the identical key prevents a new subscription.
  2. Editing a local filter changes retry behavior for the same English bundle. After the first failure, changing a to ab without clicking Retry leaves main at one load attempt; this PR starts a second. If the user does click Retry and edits the query while that retry is pending, a second chunk failure records attempt: 0 instead of 1, so the Reload button is no longer offered.

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 ocr; the base/head comparison used the actual fallback effect in a minimal React 18.3.1 test-renderer component with a controlled shared promise. This was not a browser run. The 105 passing Pages tests do not cover these sequences.

@wzxsdf

wzxsdf commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@lizhengfeng101 Thanks for catching both. Fixed in 2db42c7 by keying the fallback to the bundle itself:

  1. The fallback state no longer carries a requestKey; it is {idle|loading|ready|error} plus a single bundle-scoped attempt counter, and the effect depends only on whether anything currently needs English (a boolean: untranslated page OR active search in a partial locale) and the retry counter. Query text and the active slug are no longer inputs, so editing them neither re-keys nor cancels the subscription.
  2. Trailing space: "a" → "a " leaves the demand boolean unchanged, so the effect does not re-run or cancel; the in-flight promise settles normally.
  3. Pending retry: a retry bumps the counter and a second chunk failure records it, so the Reload button stays available; query/slug edits during the retry no longer reset the count or fire extra load attempts (re-firing still reattaches through the loader's in-flight cache — one network request).
  4. Earlier cancellation semantics are preserved: when English stops being needed, pending callbacks are still dropped, so a stale response cannot overwrite the state a main en load seeds; the zh → en → zh round trip keeps rendering cached English.

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.

@lizhengfeng101 lizhengfeng101 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.

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 5a6f77c into alibaba:main Nov 20, 2026
13 checks passed
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.

fix(pages): verify and fix partial-locale fallback recovery and fragment navigation

3 participants