Skip to content

feat(core)!: add as-needed prefetch strategy - #1711

Merged
meteorlxy merged 15 commits into
mainfrom
as-needed
Jul 24, 2026
Merged

feat(core)!: add as-needed prefetch strategy#1711
meteorlxy merged 15 commits into
mainfrom
as-needed

Conversation

@Mister-Hope

Copy link
Copy Markdown
Member

No description provided.

@Mister-Hope
Mister-Hope requested a review from meteorlxy May 19, 2026 10:51
@Mister-Hope

Mister-Hope commented May 19, 2026

Copy link
Copy Markdown
Member Author

@meteorlxy This is completed, but we should expected the following things to be preloaded as well:

  • pages appears in navbars
  • pages appears in the same sidebar group
  • pages that is prev/next

But these are theme concept, and I am not comming up with any idea how to solve this gracefully.

Any ideas for probably a new hook for themes?

@coveralls

coveralls commented May 19, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 30081445920

Coverage increased (+0.8%) to 73.948%

Details

  • Coverage increased (+0.8%) from the base build.
  • Patch coverage: 1 of 1 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1087
Covered Lines: 800
Line Coverage: 73.6%
Relevant Branches: 552
Covered Branches: 412
Branch Coverage: 74.64%
Branches in Coverage %: Yes
Coverage Strength: 48.34 hits per line

💛 - Coveralls

Comment thread packages/bundler-vite/src/build/build.ts Outdated
Comment thread packages/bundler-webpack/src/build/build.ts Outdated
let candidateFiles: string[]

return prefetchFiles
if (shouldPrefetch === 'as-needed') {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe extract this snippet to bundlerutils?

@Mister-Hope Mister-Hope Jun 24, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How? The data structures are different accross bundlers, and rely on bundler types.

@meteorlxy meteorlxy Jul 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L33-L45 is identical and duplicate across 3(4) files

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extracted to bundlerutils

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes the default prefetch strategy to an “as-needed” mode that only emits prefetch hints for chunks belonging to pages linked from the current page, enabled via a new per-page chunk-file mapping built during bundler output generation.

Changes:

  • Change shouldPrefetch default from true to 'as-needed' and extend the option type accordingly.
  • Add bundlerutils helpers (createPageChunkFilesMap, resolveLinkRoutePath, resolveLinkedPageChunkFiles) plus unit tests to support linked-page chunk discovery.
  • Extend webpack/vite build pipelines to compute and pass a PageChunkFilesMap into prefetch rendering; add E2E coverage for resource-hint behavior.

Reviewed changes

Copilot reviewed 27 out of 28 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pnpm-lock.yaml Updates workspace lock to reflect new workspace dependency usage.
packages/core/tests/app/resolveAppOptions.spec.ts Updates expectation for new shouldPrefetch default.
packages/core/src/types/app/options.ts Extends shouldPrefetch type and updates default value.
packages/core/src/app/resolveAppOptions.ts Sets new default shouldPrefetch = 'as-needed'.
packages/core/src/app/prepare/prepareRoutes.ts Exports resolvePageRedirects for reuse in mapping logic.
packages/bundlerutils/package.json Adds @vuepress/markdown dependency for MarkdownLink typing.
packages/bundlerutils/src/build/index.ts Re-exports new mapping/link-resolution utilities and types.
packages/bundlerutils/src/build/types.ts Introduces PageChunkFilesMap type.
packages/bundlerutils/src/build/resolveLinkRoutePath.ts Normalizes markdown links into route paths for map lookups.
packages/bundlerutils/src/build/resolveLinkedPageChunkFiles.ts Computes linked pages’ chunk files for “as-needed” prefetch.
packages/bundlerutils/src/build/createPageChunkFilesMap.ts Builds route/redirect → chunk-files map using resolvePageRedirects.
packages/bundlerutils/tests/build/resolveLinkRoutePath.spec.ts Unit tests for link → route normalization.
packages/bundlerutils/tests/build/resolveLinkedPageChunkFiles.spec.ts Unit tests for linked-page chunk resolution and deduping.
packages/bundlerutils/tests/build/createPageChunkFilesMap.spec.ts Unit tests for mapping final and inferred/redirect route paths to chunks.
packages/bundler-webpack/src/build/types.ts Extends client manifest to include chunk-name → output-files mapping.
packages/bundler-webpack/src/build/createClientPlugin.ts Produces clientManifest.chunks mapping from webpack stats chunks.
packages/bundler-webpack/src/build/renderPagePrefetchLinks.ts Implements 'as-needed' prefetch selection using linked-page chunks.
packages/bundler-webpack/src/build/renderPage.ts Passes page and pageChunkFilesMap into prefetch rendering.
packages/bundler-webpack/src/build/build.ts Builds pageChunkFilesMap from manifest chunk mapping and passes through.
packages/bundler-vite/src/build/renderPagePrefetchLinks.ts Implements 'as-needed' prefetch selection for rolldown dynamic imports.
packages/bundler-vite/src/build/renderPage.ts Passes page and pageChunkFilesMap into prefetch rendering.
packages/bundler-vite/src/build/build.ts Builds pageChunkFilesMap using resolvePageChunkFiles and passes through.
e2e/tests/resource-hints.spec.ts Adds E2E assertions that only linked pages’ resources are prefetched (not preloaded), including virtual pages.
e2e/docs/.vuepress/config.ts Creates a virtual source page during initialization for E2E coverage.
e2e/docs/resource-hints/source.md Adds a source page linking to linked/permalink pages for E2E.
e2e/docs/resource-hints/linked.md Adds linked page fixture.
e2e/docs/resource-hints/linked-permalink.md Adds linked page fixture with permalink frontmatter.
e2e/docs/resource-hints/unlinked.md Adds unlinked page fixture used to compute differences in E2E.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/core/src/types/app/options.ts Outdated
@meteorlxy meteorlxy changed the title feat: implement 'as-needed' prefetch and preload strategy with chunk file mapping feat!: add as-needed prefetch strategy Jul 24, 2026
@meteorlxy meteorlxy changed the title feat!: add as-needed prefetch strategy feat(core)!: add as-needed prefetch strategy Jul 24, 2026
@meteorlxy
meteorlxy merged commit 7d3da21 into main Jul 24, 2026
18 checks passed
@meteorlxy
meteorlxy deleted the as-needed branch July 24, 2026 09:13
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.

[Feature request] Improve shouldPrefetch default value [Feature request] Improve shouldPrefetch and shouldPrefetch option

4 participants