Skip to content

Commit f22108d

Browse files
authored
refactor: q-manifest for prefetching (#451)
1 parent 40a931a commit f22108d

File tree

34 files changed

+906
-446
lines changed

34 files changed

+906
-446
lines changed

packages/create-qwik/interface/log.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ export function logResult(result: GenerateResult) {
2020

2121
console.log(``);
2222

23-
console.log(`📟 ${color.cyan(`Next steps:`)}`);
23+
console.log(`🤖 ${color.cyan(`Next steps:`)}`);
2424
if (!isCwdDir) {
2525
console.log(` cd ${relativeProjectPath}`);
2626
}
2727
console.log(` npm install`);
2828
console.log(` npm start`);
2929
console.log(``);
30+
console.log(`💬 ${color.cyan('Questions? Start the conversation at:')}`);
31+
console.log(` https://qwik.builder.io/chat`);
32+
console.log(` https://twitter.com/QwikDev`);
33+
console.log(``);
3034
}
3135

3236
export function panic(msg: string) {

packages/docs/functions/[[path]].ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
// @ts-ignore
44
import { render } from '../server/entry.server.js';
5+
import type { RenderToStringOptions, RenderToStringResult } from '@builder.io/qwik/server';
6+
7+
// @ts-ignore
8+
import manifest from '../dist/q-manifest.json';
59

610
export const onRequestGet: PagesFunction = async ({ request, next, waitUntil }) => {
711
try {
@@ -11,6 +15,10 @@ export const onRequestGet: PagesFunction = async ({ request, next, waitUntil })
1115
return Response.redirect('https://qwik.builder.io/guide/overview', 302);
1216
}
1317

18+
if (url.pathname === '/chat') {
19+
return Response.redirect('https://discord.gg/bNVSQmPzqy');
20+
}
21+
1422
// Handle static assets
1523
if (/\.\w+$/.test(url.pathname) || url.pathname === '/repl/') {
1624
return next(request);
@@ -28,13 +36,21 @@ export const onRequestGet: PagesFunction = async ({ request, next, waitUntil })
2836
}
2937
}
3038

31-
// Generate Qwik SSR response
32-
const ssrResult = await render({
39+
// Render To String Options
40+
const opts: RenderToStringOptions = {
3341
url: request.url,
3442
base: '/build/',
35-
});
43+
manifest,
44+
prefetchStrategy: {
45+
symbolsToPrefetch: 'all',
46+
implementation: 'worker-fetch',
47+
},
48+
};
49+
50+
// Generate Qwik SSR response
51+
const result: RenderToStringResult = await render(opts);
3652

37-
const response = new Response(ssrResult.html, {
53+
const response = new Response(result.html, {
3854
headers: {
3955
'Cross-Origin-Embedder-Policy': 'credentialless',
4056
'Cross-Origin-Opener-Policy': 'same-origin',

packages/docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"devDependencies": {
2121
"@builder.io/partytown": "^0.5.2",
22-
"@builder.io/qwik": "0.0.19",
22+
"@builder.io/qwik": "workspace:*",
2323
"@builder.io/qwik-city": "0.0.4",
2424
"@cloudflare/kv-asset-handler": "0.2.0",
2525
"@cloudflare/workers-types": "^3.7.1",

packages/docs/src/components/repl/repl.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,13 @@ export const Repl = component$(async (props: ReplProps) => {
8989
if (location.hostname === 'localhost') {
9090
store.iframeUrl += 'index.html';
9191
}
92-
if (location.hostname === 'qwik.builder.io') {
93-
// use a different domain on purpose
94-
store.iframeUrl = 'https://qwik-docs.pages.dev' + store.iframeUrl;
95-
}
92+
93+
// TODO: enable when this ships
94+
// https://github.com/BuilderIO/qwik/commit/9fb3b9b72593c76fd80a5739a77adefd88a07651
95+
// if (location.hostname === 'qwik.builder.io') {
96+
// // use a different domain on purpose
97+
// store.iframeUrl = 'https://qwik-docs.pages.dev' + store.iframeUrl;
98+
// }
9699

97100
// how do I not use window event listener here?
98101
window.addEventListener('message', (ev) => onMessageFromIframe(ev, store));

packages/docs/src/components/repl/types.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import type {
2-
Diagnostic,
3-
QwikRollupPluginOptions,
4-
SymbolsEntryMap,
5-
} from '@builder.io/qwik/optimizer';
1+
import type { Diagnostic, QwikRollupPluginOptions, QwikManifest } from '@builder.io/qwik/optimizer';
62
import type { NoSerialize } from '@builder.io/qwik';
73

84
export interface ReplInputOptions extends Omit<QwikRollupPluginOptions, 'srcDir' | 'minify'> {
@@ -59,7 +55,7 @@ export interface ReplResult {
5955
outputHtml: string;
6056
clientModules: ReplModuleOutput[];
6157
ssrModules: ReplModuleOutput[];
62-
symbolsEntryMap: SymbolsEntryMap | null;
58+
manifest: QwikManifest | undefined;
6359
diagnostics: Diagnostic[];
6460
qwikloader: string;
6561
docElementAttributes: ReplResultAttributes;

packages/docs/src/components/repl/worker/ssr-html.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const ssrHtml = async (options: ReplInputOptions, result: ReplResult) =>
2020

2121
const ssrResult = await server.render({
2222
base: '/repl/',
23-
symbols: result.symbolsEntryMap,
23+
manifest: result.manifest,
2424
});
2525

2626
const doc = self.qwikServer.createDocument({ html: ssrResult.html });

packages/docs/src/components/repl/worker/update.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const update = async (options: ReplInputOptions) => {
1616
type: 'result',
1717
outputHtml: '',
1818
clientModules: [],
19-
symbolsEntryMap: null,
19+
manifest: undefined,
2020
ssrModules: [],
2121
diagnostics: [],
2222
docElementAttributes: {},
@@ -61,8 +61,8 @@ const bundleClient = async (options: ReplInputOptions, result: ReplResult) => {
6161
debug: options.debug,
6262
srcInputs: options.srcInputs,
6363
entryStrategy: options.entryStrategy,
64-
symbolsOutput: (s) => {
65-
result.symbolsEntryMap = s;
64+
manifestOutput: (m) => {
65+
result.manifest = m;
6666
},
6767
};
6868
console.debug('client opts', qwikRollupClientOpts);
@@ -95,7 +95,7 @@ const bundleClient = async (options: ReplInputOptions, result: ReplResult) => {
9595
});
9696

9797
result.clientModules = generated.output.map(getOutput).filter((f) => {
98-
return !f.path.endsWith('app.js') && !f.path.endsWith('symbols-manifest.json');
98+
return !f.path.endsWith('app.js') && !f.path.endsWith('q-manifest.json');
9999
});
100100

101101
console.timeEnd(`Bundle client`);
@@ -110,7 +110,7 @@ const bundleSSR = async (options: ReplInputOptions, result: ReplResult) => {
110110
debug: options.debug,
111111
srcInputs: options.srcInputs,
112112
entryStrategy: options.entryStrategy,
113-
symbolsInput: result.symbolsEntryMap,
113+
manifestInput: result.manifest,
114114
};
115115

116116
console.debug('ssr opts', qwikRollupSsrOpts);

packages/qwik/src/optimizer/src/api.md

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,21 @@ export interface HookAnalysis {
6464
// (undocumented)
6565
canonicalFilename: string;
6666
// (undocumented)
67-
entry: string | null;
67+
captures: boolean;
68+
// (undocumented)
69+
ctxKind: 'event' | 'function';
70+
// (undocumented)
71+
ctxName: string;
6872
// (undocumented)
69-
localDecl: string[];
73+
entry: string | null;
7074
// (undocumented)
71-
localIdents: string[];
75+
extension: string;
7276
// (undocumented)
7377
name: string;
7478
// (undocumented)
7579
origin: string;
80+
// (undocumented)
81+
parent: string | null;
7682
}
7783

7884
// @alpha (undocumented)
@@ -167,6 +173,36 @@ export interface Path {
167173
readonly win32: null;
168174
}
169175

176+
// @alpha (undocumented)
177+
export interface QwikBundle {
178+
// (undocumented)
179+
dynamicImports?: string[];
180+
// (undocumented)
181+
imports?: string[];
182+
// (undocumented)
183+
size: number;
184+
}
185+
186+
// @alpha (undocumented)
187+
export interface QwikManifest {
188+
// (undocumented)
189+
bundles: {
190+
[fileName: string]: QwikBundle;
191+
};
192+
// (undocumented)
193+
injections?: GlobalInjections[];
194+
// (undocumented)
195+
mapping: {
196+
[symbolName: string]: string;
197+
};
198+
// (undocumented)
199+
symbols: {
200+
[symbolName: string]: QwikSymbol;
201+
};
202+
// (undocumented)
203+
version: string;
204+
}
205+
170206
// @alpha (undocumented)
171207
export function qwikRollup(qwikRollupOpts?: QwikRollupPluginOptions): any;
172208

@@ -184,6 +220,18 @@ export interface QwikRollupPluginOptions extends BasePluginOptions {
184220
rootDir?: string;
185221
}
186222

223+
// @alpha (undocumented)
224+
export interface QwikSymbol {
225+
// (undocumented)
226+
captures: boolean;
227+
// (undocumented)
228+
ctxKind: 'function' | 'event';
229+
// (undocumented)
230+
ctxName: string;
231+
// (undocumented)
232+
parent: string | null;
233+
}
234+
187235
// @alpha (undocumented)
188236
export function qwikVite(qwikViteOpts?: QwikVitePluginOptions): any;
189237

@@ -222,18 +270,6 @@ export interface SourceLocation {
222270
// @alpha (undocumented)
223271
export type SourceMapsOption = 'external' | 'inline' | undefined | null;
224272

225-
// @alpha (undocumented)
226-
export interface SymbolsEntryMap {
227-
// (undocumented)
228-
injections?: GlobalInjections[];
229-
// (undocumented)
230-
mapping: {
231-
[canonicalName: string]: string;
232-
};
233-
// (undocumented)
234-
version: string;
235-
}
236-
237273
// @alpha (undocumented)
238274
export type SystemEnvironment = 'node' | 'deno' | 'webworker' | 'browsermain' | 'unknown';
239275

packages/qwik/src/optimizer/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export type {
1515
Optimizer,
1616
OptimizerOptions,
1717
OptimizerSystem,
18-
SymbolsEntryMap,
18+
QwikManifest,
19+
QwikBundle,
20+
QwikSymbol,
1921
SystemEnvironment,
2022
Path,
2123
SingleEntryStrategy,

0 commit comments

Comments
 (0)