-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: over-preloading due to inaccurate bundle-graph static import graph #7982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1ef8eb2
fix: over-preloading due to inaccurate bundle-graph static import graph
maiieul 96b3f8e
chore: changeset
maiieul b97a62b
chore: bring back Rollup type
maiieul d9f5de1
chore: add version check code to not show warning on >=4.52
maiieul 854d753
chore: update messages
maiieul 370b604
fix: async
maiieul 76e7f0e
chore: update warn msg
maiieul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@builder.io/qwik': minor | ||
| --- | ||
|
|
||
| FIX: Qwik now leverages Rollup's new `output.onlyExplicitManualChunks` feature, which improves preloading performance and reduces cache invalidation for a snappier user experience. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| import type { Rollup } from 'vite'; | ||
|
|
||
| import type { | ||
| Diagnostic, | ||
| EntryStrategy, | ||
|
|
@@ -18,6 +17,7 @@ import { | |
| type QwikPlugin, | ||
| type QwikPluginOptions, | ||
| } from './plugin'; | ||
| import { findDepPkgJsonPath } from './utils'; | ||
|
|
||
| type QwikRollupPluginApi = { | ||
| getOptimizer: () => Optimizer; | ||
|
|
@@ -76,7 +76,7 @@ export function qwikRollup(qwikRollupOpts: QwikRollupPluginOptions = {}): any { | |
| }, | ||
|
|
||
| outputOptions(rollupOutputOpts) { | ||
| return normalizeRollupOutputOptionsObject(qwikPlugin, rollupOutputOpts, false); | ||
| return normalizeRollupOutputOptionsObject(qwikPlugin, rollupOutputOpts, false) as any; | ||
| }, | ||
|
|
||
| async buildStart() { | ||
|
|
@@ -127,35 +127,37 @@ export function qwikRollup(qwikRollupOpts: QwikRollupPluginOptions = {}): any { | |
| return rollupPlugin; | ||
| } | ||
|
|
||
| export function normalizeRollupOutputOptions( | ||
| export async function normalizeRollupOutputOptions( | ||
| qwikPlugin: QwikPlugin, | ||
| rollupOutputOpts: Rollup.OutputOptions | Rollup.OutputOptions[] | undefined, | ||
| useAssetsDir: boolean, | ||
| outDir?: string | ||
| ): Rollup.OutputOptions | Rollup.OutputOptions[] { | ||
| ): Promise<Rollup.OutputOptions | Rollup.OutputOptions[]> { | ||
| if (Array.isArray(rollupOutputOpts)) { | ||
| // make sure at least one output is present in every case | ||
| if (!rollupOutputOpts.length) { | ||
| rollupOutputOpts.push({}); | ||
| } | ||
|
|
||
| return rollupOutputOpts.map((outputOptsObj) => ({ | ||
| ...normalizeRollupOutputOptionsObject(qwikPlugin, outputOptsObj, useAssetsDir), | ||
| dir: outDir || outputOptsObj.dir, | ||
| })); | ||
| return await Promise.all( | ||
| rollupOutputOpts.map(async (outputOptsObj) => ({ | ||
| ...(await normalizeRollupOutputOptionsObject(qwikPlugin, outputOptsObj, useAssetsDir)), | ||
| dir: outDir || outputOptsObj.dir, | ||
| })) | ||
| ); | ||
| } | ||
|
|
||
| return { | ||
| ...normalizeRollupOutputOptionsObject(qwikPlugin, rollupOutputOpts, useAssetsDir), | ||
| ...(await normalizeRollupOutputOptionsObject(qwikPlugin, rollupOutputOpts, useAssetsDir)), | ||
| dir: outDir || rollupOutputOpts?.dir, | ||
| }; | ||
| } | ||
|
|
||
| export function normalizeRollupOutputOptionsObject( | ||
| export async function normalizeRollupOutputOptionsObject( | ||
| qwikPlugin: QwikPlugin, | ||
| rollupOutputOptsObj: Rollup.OutputOptions | undefined, | ||
| useAssetsDir: boolean | ||
| ): Rollup.OutputOptions { | ||
| ): Promise<Rollup.OutputOptions> { | ||
| const outputOpts: Rollup.OutputOptions = { ...rollupOutputOptsObj }; | ||
| const opts = qwikPlugin.getOptions(); | ||
| const optimizer = qwikPlugin.getOptimizer(); | ||
|
|
@@ -253,6 +255,34 @@ export function normalizeRollupOutputOptionsObject( | |
| */ | ||
| outputOpts.hoistTransitiveImports = false; | ||
|
|
||
| // V2 official release TODO: remove below checks and just keep `outputOpts.onlyExplicitManualChunks = true;` | ||
| const userPkgJsonPath = await findDepPkgJsonPath(optimizer.sys, 'rollup', optimizer.sys.cwd()); | ||
| if (userPkgJsonPath) { | ||
| try { | ||
| const fs: typeof import('fs') = await optimizer.sys.dynamicImport('node:fs'); | ||
| const pkgJsonStr = await fs.promises.readFile(userPkgJsonPath, 'utf-8'); | ||
| const pkgJson = JSON.parse(pkgJsonStr); | ||
| const version = String(pkgJson?.version || ''); | ||
| const [major, minor, patch] = version.split('.').map((n: string) => parseInt(n, 10)) as [ | ||
| number, | ||
| number, | ||
| number, | ||
| ]; | ||
| const isGte452 = | ||
| Number.isFinite(major) && | ||
| (major > 4 || (major === 4 && (minor > 52 || (minor === 52 && (patch || 0) >= 0)))); | ||
| if (isGte452) { | ||
| outputOpts.onlyExplicitManualChunks = true; | ||
| } else { | ||
| console.warn( | ||
| `⚠️ We detected that you're using a Rollup version prior to 4.52.0 (${version}). For the latest and greatest, we recommend to let Vite install the latest version for you, or manually install the latest version of Rollup in your project if that doesn't work. It will enable the new Rollup \`outputOpts.onlyExplicitManualChunks\` feature flag, which improves preloading performance and reduces cache invalidation for a snappier user experience.` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice one 👏 we can add a link to their official doc 💡 |
||
| ); | ||
| } | ||
| } catch { | ||
| // If we cannot determine the installed Rollup version, avoid warning | ||
| } | ||
| } | ||
|
|
||
| return outputOpts; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import type { OptimizerSystem } from '../types'; | ||
|
|
||
| export async function findDepPkgJsonPath(sys: OptimizerSystem, dep: string, parent: string) { | ||
| const fs: typeof import('fs') = await sys.dynamicImport('node:fs'); | ||
| let root = parent; | ||
| while (root) { | ||
| const pkg = sys.path.join(root, 'node_modules', dep, 'package.json'); | ||
| try { | ||
| await fs.promises.access(pkg); | ||
| // use 'node:fs' version to match 'vite:resolve' and avoid realpath.native quirk | ||
| // https://github.com/sveltejs/vite-plugin-svelte/issues/525#issuecomment-1355551264 | ||
| return fs.promises.realpath(pkg); | ||
| } catch { | ||
| //empty | ||
| } | ||
| const nextRoot = sys.path.dirname(root); | ||
| if (nextRoot === root) { | ||
| break; | ||
| } | ||
| root = nextRoot; | ||
| } | ||
| return undefined; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.