Skip to content

Commit

Permalink
Only show preloading js asset warning in dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed May 7, 2024
1 parent 3340498 commit 6c30953
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-fans-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": patch
---

Only show preloading js asset warning in dev
22 changes: 12 additions & 10 deletions packages/start/src/server/StartServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ export function StartServer(props: { document: Component<DocumentComponentProps>
// @ts-ignore
const nonce = context.nonce;

let assets: Asset[] = [];
let assets: Asset[];
Promise.resolve().then(async () => {
let assetPromises: Promise<Asset[]>[] = [];
// @ts-ignore
if (context.router && context.router.matches) {
// @ts-ignore
Expand All @@ -49,17 +50,18 @@ export function StartServer(props: { document: Component<DocumentComponentProps>
const segment = matched[i];
const part = import.meta.env.MANIFEST[import.meta.env.START_ISLANDS ? "ssr" : "client"]!
.inputs[segment["$component"].src]!;
const asset = (await part.assets()) as any;
assets.push.apply(assets, asset);
assetPromises.push(part.assets() as any);
}
} else console.warn("No route matched for preloading js assets");
} else if (import.meta.env.DEV) console.warn("No route matched for preloading js assets");
}
// dedupe assets
assets = [...new Map(assets.map(item => [item.attrs.key, item])).values()].filter(asset =>
import.meta.env.START_ISLANDS
? false
: (asset.attrs as JSX.LinkHTMLAttributes<HTMLLinkElement>).rel === "modulepreload" &&
!context.assets.find((a: Asset) => a.attrs.key === asset.attrs.key)
assets = await Promise.all(assetPromises).then(a =>
// dedupe assets
[...new Map(a.flat().map(item => [item.attrs.key, item])).values()].filter(asset =>
import.meta.env.START_ISLANDS
? false
: (asset.attrs as JSX.LinkHTMLAttributes<HTMLLinkElement>).rel === "modulepreload" &&
!context.assets.find((a: Asset) => a.attrs.key === asset.attrs.key)
)
);
});

Expand Down

0 comments on commit 6c30953

Please sign in to comment.