Skip to content

Commit

Permalink
setup modulepreload anticipating vinxi update
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed Dec 15, 2023
1 parent 78a7373 commit e789de1
Show file tree
Hide file tree
Showing 21 changed files with 107 additions and 43 deletions.
2 changes: 1 addition & 1 deletion examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"@solidjs/meta": "^0.29.2",
"@solidjs/router": "^0.10.2",
"@solidjs/router": "^0.10.3",
"@solidjs/start": "^0.4.0-alpha.6",
"solid-js": "^1.8.7",
"vinxi": "0.0.51"
Expand Down
2 changes: 1 addition & 1 deletion examples/experiments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"@solidjs/meta": "^0.29.2",
"@solidjs/router": "^0.10.2",
"@solidjs/router": "^0.10.3",
"@solidjs/start": "^0.4.0-alpha.6",
"solid-js": "^1.8.7",
"vinxi": "0.0.51"
Expand Down
10 changes: 5 additions & 5 deletions examples/experiments/src/entry-client.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { mount, StartClient } from "@solidjs/start/client";

async function hello(name: string) {
"use server";
console.log("hello", name);
}
// async function hello(name: string) {
// "use server";
// console.log("hello", name);
// }

await hello("John");
// await hello("John");

mount(() => <StartClient />, document.getElementById("app"));
8 changes: 8 additions & 0 deletions examples/experiments/src/routes/(group).tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { RouteSectionProps } from "@solidjs/router";

export default function(props: RouteSectionProps) {
return <>
<h1>Group</h1>
{props.children}
</>
}
3 changes: 3 additions & 0 deletions examples/experiments/src/routes/(group)/other.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function() {
return <section>OTHER</section>
}
10 changes: 10 additions & 0 deletions examples/experiments/src/routes/test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { RouteSectionProps } from "@solidjs/router";

export default function (props: RouteSectionProps) {
return (
<>
<h1>Layout</h1>
{props.children}
</>
);
}
3 changes: 3 additions & 0 deletions examples/experiments/src/routes/test/(hi).tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function() {
return <section>CONTENT</section>
}
5 changes: 5 additions & 0 deletions examples/experiments/src/routes/test/[name].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { RouteSectionProps } from "@solidjs/router";

export default function(props: RouteSectionProps) {
return <section>{props.params.name}</section>
}
2 changes: 1 addition & 1 deletion examples/hackernews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "node ./.output/server/index.mjs"
},
"dependencies": {
"@solidjs/router": "^0.10.2",
"@solidjs/router": "^0.10.3",
"@solidjs/start": "^0.4.0-alpha.6",
"solid-js": "^1.8.7",
"vinxi": "0.0.51"
Expand Down
2 changes: 1 addition & 1 deletion examples/todomvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "node ./.output/server/index.mjs"
},
"dependencies": {
"@solidjs/router": "^0.10.2",
"@solidjs/router": "^0.10.3",
"@solidjs/start": "^0.4.0-alpha.6",
"solid-js": "^1.8.7",
"unstorage": "1.10.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/with-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@types/node": "^20.10.1"
},
"dependencies": {
"@solidjs/router": "^0.10.2",
"@solidjs/router": "^0.10.3",
"@solidjs/start": "^0.4.0-alpha.6",
"solid-js": "^1.8.7",
"vinxi": "0.0.51"
Expand Down
2 changes: 1 addition & 1 deletion examples/with-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"@mdx-js/mdx": "^2.3.0",
"@solidjs/router": "^0.10.2",
"@solidjs/router": "^0.10.3",
"@solidjs/start": "^0.4.0-alpha.6",
"@vinxi/plugin-mdx": "^3.6.5",
"solid-js": "^1.8.7",
Expand Down
2 changes: 1 addition & 1 deletion examples/with-prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@prisma/client": "^5.7.0",
"@solidjs/router": "^0.10.2",
"@solidjs/router": "^0.10.3",
"@solidjs/start": "^0.4.0-alpha.6",
"prisma": "^5.7.0",
"solid-js": "^1.8.7",
Expand Down
2 changes: 1 addition & 1 deletion examples/with-solid-styled/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"@solidjs/meta": "^0.29.2",
"@solidjs/router": "^0.10.2",
"@solidjs/router": "^0.10.3",
"@solidjs/start": "^0.4.0-alpha.6",
"solid-js": "^1.8.7",
"solid-styled": "^0.8.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/with-tailwindcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "node ./.output/server/index.mjs"
},
"dependencies": {
"@solidjs/router": "^0.10.2",
"@solidjs/router": "^0.10.3",
"@solidjs/start": "^0.4.0-alpha.6",
"autoprefixer": "^10.4.14",
"postcss": "^8.4.26",
Expand Down
2 changes: 1 addition & 1 deletion examples/with-trpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@trpc/client": "^10.44.1",
"@trpc/server": "^10.44.1",
"@solidjs/meta": "^0.29.2",
"@solidjs/router": "^0.10.2",
"@solidjs/router": "^0.10.3",
"@solidjs/start": "^0.4.0-alpha.6",
"solid-js": "^1.8.7",
"valibot": "^0.23.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.1.0",
"@solidjs/meta": "^0.29.0",
"@solidjs/router": "^0.10.2",
"@solidjs/router": "^0.10.3",
"@tailwindcss/typography": "^0.5.9",
"@trpc/client": "^9.27.4",
"@trpc/server": "^9.27.4",
Expand Down
35 changes: 34 additions & 1 deletion packages/start/server/StartServer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// @ts-ignore
import App from "#start/app";
import type { Component } from "solid-js";
import { Hydration, HydrationScript, NoHydration, getRequestEvent, ssr } from "solid-js/web";
import {
Hydration,
HydrationScript,
NoHydration,
getRequestEvent,
ssr,
useAssets
} from "solid-js/web";
import { ErrorBoundary } from "../shared/ErrorBoundary";
import { renderAsset } from "./renderAsset";
import type { DocumentComponentProps } from "./types";
Expand All @@ -10,6 +17,32 @@ const docType = ssr("<!DOCTYPE html>");

export function StartServer(props: { document: Component<DocumentComponentProps> }) {
const context = getRequestEvent() as any;

let assets = [];
Promise.resolve().then(async () => {
let current = context.routes;
if (context.routerMatches[0]) {
for (let i = 0; i < context.routerMatches[0].length; i++) {
const match = context.routerMatches[0][i];
if (match.metadata && match.metadata.filesystem) {
const segment = current.find(r => r.path === match.path);
const part = import.meta.env.MANIFEST["client"].inputs[segment["$component"].src];
const asset = await part.assets();
assets.push.apply(assets, asset);
current = segment.children;
}
}
}
// dedupe assets
assets = [...new Map(assets.map(item => [item.attrs.key, item])).values()].filter(
asset =>
asset.attrs.rel === "modulepreload" &&
!context.assets.find(a => a.attrs.key === asset.attrs.key)
);
});

useAssets(() => assets.map(m => renderAsset(m)));

return (
<NoHydration>
{docType as unknown as any}
Expand Down
3 changes: 2 additions & 1 deletion packages/start/shared/FileRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function createRoutes() {
return {
...route,
...(route.$$route ? route.$$route.require().route : undefined),
metadata: { ...(route.$$route ? route.$$route.require().route.metadata : {}), filesystem: true },
component: lazyRoute(
route.$component,
import.meta.env.START_ISLANDS
Expand All @@ -26,5 +27,5 @@ export function createRoutes() {

let routes;
export const FileRoutes = () => {
return isServer ? (getRequestEvent() as PageEvent).routes : (routes || (routes = createRoutes()));
return isServer ? (getRequestEvent() as PageEvent).routes : routes || (routes = createRoutes());
};
3 changes: 2 additions & 1 deletion packages/start/shared/lazyRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ export default function lazyRoute(
const mod = await component.import();
const Component = mod[exported];
let assets = await clientManifest.inputs?.[component.src].assets();
const styles = assets.filter((asset) => asset.tag === "style" || asset.attrs.rel === "stylesheet");
const Comp = (props) => {
return [
...assets.map((asset) => renderAsset(asset)),
...styles.map((asset) => renderAsset(asset)),
createComponent(Component, props),
];
};
Expand Down
48 changes: 24 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e789de1

Please sign in to comment.