Skip to content

Commit e77d8c5

Browse files
committed
fix(ssr): reset factor when needed
1 parent 7885598 commit e77d8c5

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/qwik/src/core/preloader/bundle-graph.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
maxSignificantInverseProbabilityStr,
66
maxSimultaneousPreloadsStr,
77
} from './constants';
8-
import { adjustProbabilities, bundles, log, trigger } from './queue';
8+
import { adjustProbabilities, bundles, log, shouldResetFactor, trigger } from './queue';
99
import type { BundleGraph, BundleImport, ImportProbability } from './types';
1010
import { BundleImportState_None, BundleImportState_Alias } from './types';
1111

@@ -22,7 +22,7 @@ const makeBundle = (name: string, deps?: ImportProbability[]) => {
2222
$name$: name,
2323
$url$: url,
2424
$state$: url ? BundleImportState_None : BundleImportState_Alias,
25-
$deps$: deps,
25+
$deps$: shouldResetFactor ? deps?.map((d) => ({ ...d, $factor$: 1 })) : deps,
2626
$inverseProbability$: 1,
2727
$createdTs$: Date.now(),
2828
$waitedMs$: 0,

packages/qwik/src/core/preloader/queue.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
} from './types';
1818

1919
export const bundles: BundleImports = new Map();
20+
export let shouldResetFactor: boolean;
2021
let queueDirty: boolean;
2122
let preloadCount = 0;
2223
const queue: BundleImport[] = [];
@@ -32,6 +33,7 @@ export const log = (...args: any[]) => {
3233
export const resetQueue = () => {
3334
bundles.clear();
3435
queueDirty = false;
36+
shouldResetFactor = true;
3537
preloadCount = 0;
3638
queue.length = 0;
3739
};
@@ -178,6 +180,7 @@ export const adjustProbabilities = (
178180
if (bundle.$deps$) {
179181
seen ||= new Set();
180182
seen.add(bundle);
183+
const probability = 1 - bundle.$inverseProbability$;
181184
for (const dep of bundle.$deps$) {
182185
const depBundle = getBundle(dep.$name$)!;
183186
const prevAdjust = dep.$factor$;
@@ -188,7 +191,7 @@ export const adjustProbabilities = (
188191
* We can multiply this chance together with all other bundle adjustments to get the chance
189192
* that a dep will be loaded given all the chances of the other bundles
190193
*/
191-
const newInverseProbability = 1 - dep.$probability$ * (1 - bundle.$inverseProbability$);
194+
const newInverseProbability = 1 - dep.$probability$ * probability;
192195

193196
/** We need to undo the previous adjustment */
194197
const factor = newInverseProbability / prevAdjust;

0 commit comments

Comments
 (0)