Skip to content

Commit 0dae1e2

Browse files
committed
fix(preloader): don't queue until initialization
1 parent 05cf787 commit 0dae1e2

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ test('preloader script', () => {
2121
* dereference objects etc, but that actually results in worse compression
2222
*/
2323
const compressed = compress(Buffer.from(preLoader), { mode: 1, quality: 11 });
24-
expect([compressed.length, preLoader.length]).toEqual([1851, 5535]);
24+
expect([compressed.length, preLoader.length]).toEqual([1878, 5614]);
2525
});

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ export const adjustProbabilities = (
168168
}
169169

170170
if (
171+
// don't queue until we have initialized the preloader
172+
base != null &&
171173
bundle.$state$ < BundleImportState_Preload &&
172174
bundle.$inverseProbability$ < config.$invPreloadProbability$
173175
) {
@@ -192,7 +194,6 @@ export const adjustProbabilities = (
192194
// it's already at max probability
193195
continue;
194196
}
195-
const prevAdjust = dep.$factor$;
196197
/**
197198
* The chance that a dep won't be loaded is 1-(the chance that the dep will be loaded)*(the
198199
* chance that the current bundle will be loaded).
@@ -213,13 +214,14 @@ export const adjustProbabilities = (
213214
newInverseProbability = Math.min(0.01, 1 - dep.$importProbability$);
214215
} else {
215216
const newInverseImportProbability = 1 - dep.$importProbability$ * probability;
217+
/** We need to undo the previous adjustment */
218+
const prevAdjust = dep.$factor$;
216219
const factor = newInverseImportProbability / prevAdjust;
217220
// limit organic probability to 98%
218221
newInverseProbability = Math.max(0.02, depBundle.$inverseProbability$ * factor);
219222
dep.$factor$ = factor;
220223
}
221224

222-
/** We need to undo the previous adjustment */
223225
adjustProbabilities(depBundle, newInverseProbability, seen);
224226
}
225227
}
@@ -228,7 +230,7 @@ export const adjustProbabilities = (
228230
export const handleBundle = (name: string, inverseProbability: number) => {
229231
const bundle = getBundle(name);
230232
if (bundle && bundle.$inverseProbability$ > inverseProbability) {
231-
adjustProbabilities(bundle, inverseProbability / bundle.$inverseProbability$);
233+
adjustProbabilities(bundle, inverseProbability);
232234
}
233235
};
234236

0 commit comments

Comments
 (0)