Skip to content

Commit 41cb35e

Browse files
authored
Merge pull request #7453 from QwikDev/dynamic-modulepreload
feat: dynamic modulepreload
2 parents b3ff7a7 + a3fa86b commit 41cb35e

File tree

154 files changed

+6343
-4009
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+6343
-4009
lines changed

.changeset/fair-cars-fry.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@builder.io/qwik': minor
3+
---
4+
5+
PERF: Prefetching now happens dynamically without service worker if the prefetchImplementation is set to "html-append" (default).
6+
PERF: Initial prefetching now includes dynamic imports, which improves initial click delay.

.changeset/yellow-frogs-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@builder.io/qwik-city': minor
3+
---
4+
5+
CHORE: the service workers have been deprecated and replaced with entries that unregister them. If you have it enabled in production, you can remove it after a while once you are sure all your users have the new version.

packages/docs/src/entry.ssr.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { renderToStream, type RenderToStreamOptions } from '@builder.io/qwik/server';
2-
import { manifest } from '@qwik-client-manifest';
32
import Root from './root';
43

54
export default function (opts: RenderToStreamOptions) {
65
return renderToStream(<Root />, {
7-
manifest,
86
qwikLoader: {
97
// The docs can be long so make sure to intercept events before the end of the document.
108
position: 'top',

packages/docs/src/repl/bundled.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import qCoreDts from '../../node_modules/@builder.io/qwik/dist/core.d.ts?raw-sou
1414
import qCoreMinMjs from '../../node_modules/@builder.io/qwik/dist/core.min.mjs?raw-source';
1515
import qCoreMjs from '../../node_modules/@builder.io/qwik/dist/core.mjs?raw-source';
1616
import qOptimizerCjs from '../../node_modules/@builder.io/qwik/dist/optimizer.cjs?raw-source';
17+
import qPreloaderMjs from '../../node_modules/@builder.io/qwik/dist/preloader.mjs?raw-source';
1718
import qServerCjs from '../../node_modules/@builder.io/qwik/dist/server.cjs?raw-source';
1819
import qServerDts from '../../node_modules/@builder.io/qwik/dist/server.d.ts?raw-source';
1920
import qWasmCjs from '../../node_modules/@builder.io/qwik/bindings/qwik.wasm.cjs?raw-source';
@@ -55,6 +56,7 @@ export const bundled: PkgUrls = {
5556
'/dist/optimizer.cjs': qOptimizerCjs,
5657
'/dist/server.cjs': qServerCjs,
5758
'/dist/server.d.ts': qServerDts,
59+
'/dist/preloader.mjs': qPreloaderMjs,
5860
'/bindings/qwik.wasm.cjs': qWasmCjs,
5961
'/bindings/qwik_wasm_bg.wasm': qWasmBinUrl,
6062
},

packages/docs/src/repl/repl-output-modules.tsx

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { $, component$, useSignal } from '@builder.io/qwik';
1+
import { $, component$, createSignal, useSignal } from '@builder.io/qwik';
22
import { CodeBlock } from '../components/code-block/code-block';
33
import type { ReplModuleOutput } from './types';
44
const FILE_MODULE_DIV_ID = 'file-modules-client-modules';
@@ -35,22 +35,34 @@ export const ReplOutputModules = component$(({ outputs, headerText }: ReplOutput
3535
</div>
3636
</div>
3737
<div class="file-modules" id={FILE_MODULE_DIV_ID}>
38-
{outputs.map((o, i) => (
39-
<div class="file-item" data-output-item={i} key={o.path}>
40-
<div class="file-info">
41-
<span>{o.path}</span>
42-
{o.size ? <span class="file-size">({o.size})</span> : null}
38+
{outputs.map((o, i) => {
39+
const isLarge = o.code.length > 3000;
40+
if (isLarge && !o.shorten) {
41+
o.shorten = createSignal(true);
42+
}
43+
const code = o.shorten?.value ? o.code.slice(0, 3000) : o.code;
44+
return (
45+
<div class="file-item" data-output-item={i} key={o.path}>
46+
<div class="file-info">
47+
<span>{o.path}</span>
48+
{o.size ? <span class="file-size">({o.size})</span> : null}
49+
</div>
50+
<div class="file-text">
51+
<CodeBlock
52+
pathInView$={pathInView$}
53+
path={o.path}
54+
code={code}
55+
observerRootId={FILE_MODULE_DIV_ID}
56+
/>
57+
{o.shorten && (
58+
<button onClick$={() => (o.shorten.value = !o.shorten.value)}>
59+
{o.shorten.value ? 'Truncated - show more' : 'Show less'}
60+
</button>
61+
)}
62+
</div>
4363
</div>
44-
<div class="file-text">
45-
<CodeBlock
46-
pathInView$={pathInView$}
47-
path={o.path}
48-
code={o.code}
49-
observerRootId={FILE_MODULE_DIV_ID}
50-
/>
51-
</div>
52-
</div>
53-
))}
64+
);
65+
})}
5466
</div>
5567
</div>
5668
);

packages/docs/src/repl/repl-output-panel.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { component$, useComputed$ } from '@builder.io/qwik';
1+
import { component$ } from '@builder.io/qwik';
22
import { CodeBlock } from '../components/code-block/code-block';
33
import { ReplOutputModules } from './repl-output-modules';
44
import { ReplOutputSymbols } from './repl-output-symbols';
@@ -8,10 +8,6 @@ import type { ReplAppInput, ReplStore } from './types';
88

99
export const ReplOutputPanel = component$(({ input, store }: ReplOutputPanelProps) => {
1010
const diagnosticsLen = store.diagnostics.length + store.monacoDiagnostics.length;
11-
const clientBundlesNoCore = useComputed$(() =>
12-
// Qwik Core is not interesting and is large, slowing down the UI
13-
store.clientBundles.filter((b) => !b.path.endsWith('qwikCore.js'))
14-
);
1511

1612
return (
1713
<div class="repl-panel repl-output-panel">
@@ -115,7 +111,7 @@ export const ReplOutputPanel = component$(({ input, store }: ReplOutputPanelProp
115111
) : null}
116112

117113
{store.selectedOutputPanel === 'clientBundles' ? (
118-
<ReplOutputModules headerText="/build/" outputs={clientBundlesNoCore.value} />
114+
<ReplOutputModules headerText="/build/" outputs={store.clientBundles} />
119115
) : null}
120116

121117
{store.selectedOutputPanel === 'serverModules' ? (

packages/docs/src/repl/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import type { NoSerialize, Signal } from '@builder.io/qwik';
12
import type {
23
Diagnostic,
34
QwikManifest,
45
QwikRollupPluginOptions,
56
TransformModule,
67
} from '@builder.io/qwik/optimizer';
7-
import type { NoSerialize } from '@builder.io/qwik';
88

99
export interface ReplAppInput {
1010
buildId: number;
@@ -58,6 +58,7 @@ export interface ReplModuleOutput {
5858
path: string;
5959
code: string;
6060
size?: string;
61+
shorten?: Signal<boolean>;
6162
}
6263

6364
export interface ReplMessageBase {

packages/docs/src/repl/worker/app-bundle-client.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,6 @@ export const appBundleClient = async (
104104
});
105105
}
106106

107-
result.transformedModules = result.transformedModules.filter((f) => {
108-
return (
109-
!f.path.endsWith('app.js') &&
110-
!f.path.endsWith('entry.server.js') &&
111-
!f.path.endsWith('root.js')
112-
);
113-
});
114-
115107
result.events.push({
116108
kind: 'console-log',
117109
scope: 'build',

packages/docs/src/repl/worker/repl-plugins.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export const replResolver = (options: ReplInputOptions, buildMode: 'client' | 's
2929
if (id === '@builder.io/qwik/server') {
3030
return '\0qwikServer';
3131
}
32+
if (id === '@builder.io/qwik/preloader') {
33+
return '\0qwikPreloader';
34+
}
3235
// Simple relative file resolution
3336
if (id.startsWith('./')) {
3437
const extensions = ['', '.tsx', '.ts'];
@@ -69,6 +72,12 @@ export const replResolver = (options: ReplInputOptions, buildMode: 'client' | 's
6972
}
7073
throw new Error(`Unable to load Qwik core`);
7174
}
75+
if (id === '\0qwikPreloader') {
76+
const rsp = await depResponse('@builder.io/qwik', '/preloader.mjs');
77+
if (rsp) {
78+
return rsp.text();
79+
}
80+
}
7281

7382
// We're the fallback, we know all the files
7483
if (/\.[jt]sx?$/.test(id)) {

packages/docs/src/root.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { component$, useContextProvider, useStore } from '@builder.io/qwik';
22
import { QwikCityProvider, RouterOutlet, ServiceWorkerRegister } from '@builder.io/qwik-city';
3+
import { Insights } from '@builder.io/qwik-labs';
34
import RealMetricsOptimization from './components/real-metrics-optimization/real-metrics-optimization';
45
import { RouterHead } from './components/router-head/router-head';
6+
import { BUILDER_PUBLIC_API_KEY } from './constants';
57
import { GlobalStore, type SiteStore } from './context';
68
import './global.css';
7-
import { BUILDER_PUBLIC_API_KEY } from './constants';
8-
import { Insights } from '@builder.io/qwik-labs';
99

1010
export const uwu = /*javascript*/ `
1111
;(function () {

0 commit comments

Comments
 (0)