Skip to content

perf(pages): lazy-load documentation content by language #1895

Closed

Description

@lizhengfeng101

Description

The documentation content index statically imports the Markdown bodies for all five languages. Opening a single documentation page therefore loads every language's content through the documentation route chunk, even when the reader never changes language.

Split documentation content by language while preserving the current reading, navigation, and full-text search experience. This is a content-loading change, not a redesign of the documentation site or search behavior.

Implement three layers:

  1. Lightweight directory: keep document slugs, navigation order, and language availability separate from Markdown bodies. Importing the directory must not load any document body.
  2. Five language content bundles: load en, zh, ja, ko, and ru through explicit import() boundaries. Load the selected language on demand, share in-flight requests, and cache successful loads for subsequent navigation. Moving between articles in a loaded language must not download its content again; changing language loads the newly selected language only when needed.
  3. Shared page/search data: render pages and run the existing full-text search against the same loaded language content. Preserve matching, result order, titles, and contextual snippets. Do not introduce a separate search service or index.

Keep the navigation and page shell visible while content loads, with a loading state confined to the content area. Ignore stale responses after a newer language selection. Failed loads must expose a retry action and must not permanently poison the loading cache.

Preserve English fallback without downloading English speculatively. Language availability in the directory determines whether a translation is missing. Load English when a requested page needs fallback, or when a non-empty search in a partial locale needs English entries to preserve current search coverage. A transient download failure is not evidence that a translation is missing and should remain retryable.

Scope

  • pages/src/content/docs/index.ts: separate directory metadata, language content loading, content/title access, and search inputs.
  • Language content modules under pages/src/content/docs/: establish the five asynchronous content boundaries while retaining the existing Markdown sources.
  • pages/src/pages/DocsPage.tsx: loading/error/retry states, language-switch races, and integration with page rendering, search, headings, and navigation.
  • pages/src/hooks/useCommandSearch.ts: preserve the search contract during asynchronous content availability; any shared-hook changes must not regress blog search.
  • Relevant content-loading, page, navigation, and search tests; production bundle/network verification.

Out of scope: per-article splitting, external search services, a separate search index, a framework migration, homepage animation optimization, Mermaid optimization, and changes to documentation URLs or content semantics. Do not preload or prefetch all languages in the background, and do not raise bundle-size warning limits as a substitute for reducing unnecessary downloads.

Acceptance Criteria

  • Importing the directory or rendering the documentation shell does not eagerly import any Markdown body or all-language content map.
  • With an empty cache, opening a translated documentation page downloads the selected language's content, not the other four language bundles. Each language is independently loadable.
  • Navigating to another article in the same language reuses the loaded content. Re-selecting a successfully loaded language reuses its cache; concurrent consumers share the same in-flight load.
  • Navigation and the page shell remain visible while loading. Rapid language changes cannot allow an older response to replace the current language's page, title, headings, or search results.
  • A failed load shows an actionable error and can be retried successfully without a full-page reload. Failure is not cached as a successful or permanently rejected result.
  • English fallback remains correct for missing translations and unsupported languages. A page with an available translation does not trigger an unconditional English download. Tests include a partial-locale fixture even if the current shipped translations are complete.
  • Search retains the current case-insensitive full-body matching, ordering, contextual snippets, and English-fallback coverage. Search opened before content is ready shows a loading/error state rather than a misleading empty result; the current query is evaluated once its data is ready. Blog search remains unchanged.
  • Existing document URLs, direct links with fragments, heading IDs, table of contents, language switching, and browser back/forward navigation continue working after asynchronous loading. Fragment scrolling occurs after the requested content has rendered.
  • Add regression tests for caching/request sharing, out-of-order language responses, failure followed by successful retry, fallback, search readiness/compatibility, and deep-link/navigation behavior.
  • Provide before/after production-build and cold-cache browser Network evidence for the same document and language. Show reduced transferred documentation content and that unused languages are not fetched, including after the page settles. Distinguish uncompressed bundle sizes from actual compressed transfer sizes; disappearing webpack warnings alone is not sufficient evidence.
  • Run make check and the site's documented checks: npm --prefix pages run lint, npm --prefix pages test, npm --prefix pages run typecheck, npm --prefix pages run build, and npm --prefix pages run size. Report any existing unrelated failures separately rather than weakening checks.

Context

Discovered while investigating documentation bundle-size warnings during the follow-up to #1894. The eager all-language imports are an existing site architecture issue, not a regression caused by removing --tools.

Relevant current behavior at a7639986bbc1358787c29926331a93c7e154ed96:

AI/LLM disclosure

OpenAI Codex assisted with repository inspection and drafting this issue from the maintainer's requested direction. The drafting model identifier is not exposed to the assistant in this session and is therefore not claimed here.

Activity

  1. added
    enhancement
    i18n
    good first issue
    on Nov 10, 2026
  2. ngocanh310819933-coder commented on Nov 10, 2026

    @ngocanh310819933-coder

    Vang ạ

  3. ngocanh310819933-coder commented on Nov 10, 2026

    @ngocanh310819933-coder

    Mà mình đang làm gì thế

  4. YaoSong808 commented on Nov 10, 2026

    @YaoSong808

    Hi, I’d like to work on this. I reproduced the issue on current main: the docs page chunk is about 1.46 MiB and contains all five language bundles.

    I plan to split directory metadata from language content, add cached on-demand loading with retry support, and update the page and search tests for fallback and race conditions.

    AI/LLM disclosure: I’ll use OpenAI Codex (GPT-5) for repository inspection, implementation, testing, and PR preparation. I’ll review and understand all changes before submission.

  5. wzxsdf commented on Nov 18, 2026

    @wzxsdf
    Contributor

    @lizhengfeng101
    Hi, I'd like to give this a try.

    I've reviewed the current implementation — pages/src/content/docs/index.ts statically imports all 95 Markdown files across five languages, so the plan is clear and well-scoped: a lightweight directory module, per-language bundles behind import() with cached, shared in-flight loads, and page/search reading from the loaded language content.

    I noticed #1896 (draft) targets the same issue but has been inactive since Nov 10 (one commit, unresolved automated findings, CLA unsigned). If YaoSong808 still plans to continue it, I'm happy to pick something else instead; otherwise I'd like to take this up and will take the existing review feedback into account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issuei18n

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions