Skip to content

Commit cef0ec8

Browse files
committed
make asset manifest naming a bit clearer
1 parent b2bea15 commit cef0ec8

5 files changed

Lines changed: 50 additions & 15 deletions

File tree

packages/start/src/config/index.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ function solidStartVitePlugin(options?: SolidStartOptions): Array<PluginOption>
225225
const manifest: StartServerManifest = {
226226
clientEntryId: normalizePath(handlers.client),
227227
clientViteManifest: {},
228-
routes: {}
228+
clientAssetManifest: {}
229229
};
230230

231231
return `export const manifest = ${JSON.stringify(manifest)}`;
@@ -236,20 +236,41 @@ function solidStartVitePlugin(options?: SolidStartOptions): Array<PluginOption>
236236
);
237237
if (!entry) throw new Error("No client entry found");
238238

239-
const clientManifest: Record<string, { file: string }> = JSON.parse(
239+
const clientManifest: Record<string, Record<string, any>> = JSON.parse(
240240
(globalThis.START_CLIENT_BUNDLE[".vite/manifest.json"] as any).source
241241
);
242242

243-
const routes = Object.entries(clientManifest).reduce((acc, [id, entry]) => {
244-
acc[id] = { output: `/${CLIENT_BASE_PATH}/${entry.file}` };
243+
const clientAssetManifest = Object.entries(clientManifest).reduce((acc, [id, entry]) => {
244+
const assets = [
245+
...(entry.assets?.filter(Boolean) || []),
246+
...(entry.css?.filter(Boolean) || [])
247+
]
248+
.filter(
249+
(asset) =>
250+
asset.endsWith(".css") ||
251+
asset.endsWith(".js") ||
252+
asset.endsWith(".mjs"),
253+
)
254+
.map((asset) => ({
255+
tag: "link",
256+
attrs: {
257+
href: join("/", CLIENT_BASE_PATH, asset),
258+
key: join("/", CLIENT_BASE_PATH, asset),
259+
...(asset.endsWith(".css")
260+
? { rel: "stylesheet", fetchPriority: "high" }
261+
: { rel: "modulepreload" }),
262+
},
263+
} satisfies ManifestAsset));
264+
;
265+
266+
acc[id] = { output: `/${CLIENT_BASE_PATH}/${entry.file}`, assets };
245267
return acc;
246-
}, {} as Record<string, { output: string }>);
268+
}, {} as ClientManifest);
247269

248270
const manifest: StartServerManifest = {
249271
clientEntryId: normalizePath(handlers.client),
250-
// clientEntry: `/${CLIENT_BASE_PATH}/${entry.fileName}`,
251272
clientViteManifest: clientManifest,
252-
routes
273+
clientAssetManifest
253274
};
254275

255276
return `export const manifest = ${JSON.stringify(manifest)};`;

packages/start/src/server/StartServer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function StartServer(props: { document: Component<DocumentComponentProps>
9999
<>
100100
<script
101101
nonce={nonce}
102-
innerHTML={`window.manifest = ${JSON.stringify(manifest.routes)}`}
102+
innerHTML={`window.manifest = ${JSON.stringify(manifest.clientAssetManifest)}`}
103103
/>
104104
<script type="module" nonce={nonce} async src={getClientEntryPath()} />
105105
</>

packages/start/src/server/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export async function createPageEvent(ctx: FetchEvent) {
6767
// const prevPath = ctx.request.headers.get("x-solid-referrer");
6868
// const mutation = ctx.request.headers.get("x-solid-mutation") === "true";
6969
const pageEvent: PageEvent = Object.assign(ctx, {
70-
manifest: manifest.routes,
70+
manifest: manifest.clientAssetManifest,
7171
assets: [
7272
...getClientEntryCssTags()
7373
// not needed anymore?

packages/start/src/server/spa/StartServer.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ export function StartServer(props: { document: Component<DocumentComponentProps>
2929
<>
3030
<script
3131
nonce={nonce}
32-
innerHTML={`window.manifest = ${JSON.stringify(manifest.routes)}`}
32+
innerHTML={`window.manifest = ${JSON.stringify(manifest.clientAssetManifest)}`}
3333
/>
3434
<script type="module" nonce={nonce} async src={getClientEntryPath()} />
3535
</>
3636
) : (
3737
<>
38-
<script innerHTML={`window.manifest = ${JSON.stringify(manifest.routes)}`} />
38+
<script
39+
innerHTML={`window.manifest = ${JSON.stringify(manifest.clientAssetManifest)}`}
40+
/>
3941
<script type="module" nonce={nonce} async src={getClientEntryPath()} />
4042
</>
4143
)

packages/start/src/virtual.d.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1+
type LinkAssetAttrs = { href: string, key: string } & (
2+
{ rel: "stylesheet", fetchPriority?: string }
3+
| { rel: "modulepreload" });
4+
5+
type ManifestAsset = {
6+
tag: "link",
7+
attrs: LinkAssetAttrs
8+
}
9+
10+
type ClientManifest = Record<string, {
11+
output: string,
12+
assets?: Array<ManifestAsset>
13+
}>;
14+
115
declare module "solid-start:server-manifest" {
216
interface StartServerManifest {
317
clientEntryId: string;
418
clientViteManifest: Record<string, { css?: Array<string>, file?: string, [key: string]: unknown }>;
5-
routes: Record<string, { output: string }>;
19+
clientAssetManifest: ClientManifest;
620
}
721

822
export const manifest: StartServerManifest;
923
}
1024

1125
declare module "solid-start:client-prod-manifest" {
12-
type Manifest = Record<string, { output: string }>;
13-
14-
export default {} as Manifest;
26+
export default {} as ClientManifest;
1527
}
1628

1729
declare module "#start/app" {

0 commit comments

Comments
 (0)