Skip to content

Commit fae5e29

Browse files
committed
chore: after rebase fixes
1 parent fa64cfd commit fae5e29

9 files changed

Lines changed: 4392 additions & 656 deletions

File tree

packages/qwik/src/core/bench/bench-results.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"dom-table-10": 0,
7373
"dom-table-1k": 0,
7474
"serialize-state-1k": 96844,
75-
"ssr-table-10": 2449,
76-
"ssr-table-1k": 177675
75+
"ssr-table-10": 2175,
76+
"ssr-table-1k": 177401
7777
}
7878
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createMacroTask } from '../shared/platform/next-tick';
2-
import { config, isJSRegex, isRunningOnBrowser, yieldInterval } from './constants';
2+
import { config, isJSRegex, isBrowser, yieldInterval } from './constants';
33
import { adjustProbabilities, bundles, shouldResetFactor, nextTriggerMacroTask } from './queue';
44
import type { BundleGraph, BundleImport, ImportProbability } from './types';
55
import { BundleImportState_None, BundleImportState_Alias } from './types';
@@ -77,7 +77,7 @@ export const loadBundleGraph = (
7777
config.$maxIdlePreloads$ = opts['P'] as number;
7878
}
7979
}
80-
if (!isRunningOnBrowser || basePath == null) {
80+
if (!isBrowser || basePath == null) {
8181
return;
8282
}
8383
base = basePath;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { isBrowser } from '@qwik.dev/core/build';
1+
import { isServer } from '@qwik.dev/core/build';
22
import { qTest } from '../shared/utils/qdev';
33
import { isServerPlatform } from '../shared/platform/platform';
44

5-
export const isRunningOnBrowser = qTest ? !isServerPlatform() : isBrowser;
5+
const hasDocument = typeof document !== 'undefined';
6+
7+
export const isBrowser = (qTest ? !isServerPlatform() : !isServer) && hasDocument;
68

79
// Browser-specific setup
8-
export const doc = isRunningOnBrowser ? document : undefined!;
10+
export const doc = isBrowser ? document : undefined!;
911

1012
export const config = {
1113
$DEBUG$: false,
@@ -14,7 +16,7 @@ export const config = {
1416

1517
// Determine which rel attribute to use based on browser support
1618
export const rel =
17-
isRunningOnBrowser && doc.createElement('link').relList?.supports?.('modulepreload')
19+
isBrowser && doc.createElement('link').relList?.supports?.('modulepreload')
1820
? 'modulePreload'
1921
: 'preload';
2022

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test('preloader script', async () => {
3333
const compressed = compress(Buffer.from(code), { mode: 1, quality: 11 });
3434
expect({ brotli: compressed.length, minified: code.length }).toMatchInlineSnapshot(`
3535
{
36-
"brotli": 1354,
36+
"brotli": 1360,
3737
"minified": 2923,
3838
}
3939
`);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { base, getBundle } from './bundle-graph';
2-
import { config, doc, isRunningOnBrowser, rel, yieldInterval } from './constants';
2+
import { config, doc, isBrowser, rel, yieldInterval } from './constants';
33
import type { BundleImport, BundleImports, ImportProbability } from './types';
44
import {
55
BundleImportState_Loaded,
@@ -180,13 +180,13 @@ function processPendingAdjustments() {
180180

181181
isAdjustmentScheduled = false;
182182
isProcessingAdjustments = true;
183-
const deadline = isRunningOnBrowser ? performance.now() + yieldInterval : 0;
183+
const deadline = isBrowser ? performance.now() + yieldInterval : 0;
184184
let processed = false;
185185

186186
while (adjustmentStack.length) {
187187
processed = true;
188188
const checkDeadline = processAdjustmentFrame();
189-
if (isRunningOnBrowser && checkDeadline && performance.now() >= deadline) {
189+
if (isBrowser && checkDeadline && performance.now() >= deadline) {
190190
if (!isAdjustmentScheduled) {
191191
isAdjustmentScheduled = true;
192192
nextAdjustmentMacroTask();
@@ -197,7 +197,7 @@ function processPendingAdjustments() {
197197

198198
isProcessingAdjustments = false;
199199

200-
if (processed && isRunningOnBrowser) {
200+
if (processed && isBrowser) {
201201
nextTriggerMacroTask();
202202
}
203203
}
@@ -248,7 +248,7 @@ export const adjustProbabilities = (
248248
seen?: Set<BundleImport>
249249
) => {
250250
enqueueAdjustment(bundle, newInverseProbability, seen);
251-
if (isRunningOnBrowser) {
251+
if (isBrowser) {
252252
nextAdjustmentMacroTask();
253253
} else {
254254
processPendingAdjustments();
@@ -276,14 +276,14 @@ export const preload = (item: string | string[], probability?: number) => {
276276
} else {
277277
handleBundle(item, inverseProbability);
278278
}
279-
if (isRunningOnBrowser) {
279+
if (isBrowser) {
280280
nextAdjustmentMacroTask();
281281
} else {
282282
processPendingAdjustments();
283283
}
284284
};
285285

286-
if (isRunningOnBrowser) {
286+
if (isBrowser) {
287287
// Get early hints from qwikloader
288288
document.addEventListener('qsymbol', (ev) => {
289289
const { symbol, href } = (ev as QwikSymbolEvent).detail;

packages/qwik/src/core/use/use-locale.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { tryGetInvokeContext } from './use-core';
22
import { getAsyncLocalStorage } from '../shared/platform/async-local-storage';
33
import { isServer } from '@qwik.dev/core/build';
4-
import { getAsyncLocalStorage } from '../shared/platform/async-local-storage';
54
import type { AsyncLocalStorage } from 'node:async_hooks';
65

76
let _locale: string | undefined = undefined;

packages/qwik/src/server/preload-impl.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { getPlatform } from '@qwik.dev/core';
2-
import { isDev } from '@qwik.dev/core/build';
32
import { initPreloader, qTest } from './qwik-copy';
43
import type { QRLInternal, SSRContainer } from './qwik-types';
54
import type { PreloaderOptions, RenderOptions, RenderToStreamOptions } from './types';
@@ -44,7 +43,7 @@ export const preloaderPre = (
4443
bundleGraphPath = (import.meta.env?.BASE_URL || '/') + bundleGraphPath;
4544
}
4645
if (
47-
!(isDev && !import.meta.env.TEST) &&
46+
!(import.meta.env?.DEV && !qTest) &&
4847
preloaderBundle &&
4948
bundleGraphPath &&
5049
options !== false
@@ -194,7 +193,7 @@ export const includePreloader = (
194193
};
195194

196195
export const preloaderPost = (ssrContainer: SSRContainer, opts: RenderOptions, nonce?: string) => {
197-
if (isDev && !import.meta.env.TEST) {
196+
if (import.meta.env?.DEV && !qTest) {
198197
return;
199198
}
200199
if (opts.preloader !== false) {

packages/qwik/src/server/preload-impl.unit.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,18 @@ const createContainer = () => {
3535

3636
describe('preloader', () => {
3737
afterEach(() => {
38+
vi.doUnmock('./qwik-copy');
3839
vi.unstubAllEnvs();
3940
vi.resetModules();
4041
});
4142

4243
it('does not emit preloader assets or scripts in dev mode', async () => {
4344
vi.stubEnv('DEV', true);
44-
vi.stubEnv('TEST', '');
45+
vi.doMock('./qwik-copy', () => ({
46+
initPreloader: vi.fn(),
47+
qTest: false,
48+
}));
49+
vi.resetModules();
4550

4651
const { container, elements, getScriptContent } = createContainer();
4752
const { preloaderPost, preloaderPre } = await import('./preload-impl');

0 commit comments

Comments
 (0)