Skip to content

Commit

Permalink
make tests work
Browse files Browse the repository at this point in the history
  • Loading branch information
nksaraf committed Jul 31, 2023
1 parent ef8aee3 commit 26f2f10
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 43 deletions.
28 changes: 15 additions & 13 deletions examples/react/ssr/basic/app/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ export default eventHandler(async (event) => {
const clientManifest = import.meta.env.MANIFEST["client"];
const assets = await clientManifest.inputs[clientManifest.handler].assets();
const events = {};
const stream = renderToPipeableStream(
<App assets={<Suspense>{assets.map((m) => renderAsset(m))}</Suspense>} />,
{
onAllReady: () => {
events["end"]?.();
const stream = await new Promise(async (resolve) => {
const stream = renderToPipeableStream(
<App assets={<Suspense>{assets.map((m) => renderAsset(m))}</Suspense>} />,
{
onShellReady() {
resolve(stream);
},
bootstrapModules: [
clientManifest.inputs[clientManifest.handler].output.path,
],
bootstrapScriptContent: `window.manifest = ${JSON.stringify(
await clientManifest.json(),
)}`,
},
bootstrapModules: [
clientManifest.inputs[clientManifest.handler].output.path,
],
bootstrapScriptContent: `window.manifest = ${JSON.stringify(
await clientManifest.json(),
)}`,
},
);
);
});

// @ts-ignore
stream.on = (event, listener) => {
Expand Down
7 changes: 4 additions & 3 deletions packages/vinxi/lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const buildRouterSchema = v.object({
build: v.object({
outDir: v.string().optional(),
target: v.literal("browser"),
plugins: v.custom((value) => typeof value === "function"),
plugins: v.optional(v.custom((value) => typeof value === "function")),
}),
});

Expand All @@ -113,7 +113,7 @@ const handlerRouterSchema = v.object({
),
outDir: v.string().optional(),
target: v.literal("node"),
plugins: v.custom((value) => typeof value === "function"),
plugins: v.optional(v.custom((value) => typeof value === "function")),
}),
});

Expand All @@ -131,7 +131,8 @@ const spaRouterSchema = v.object({
build: v.object({
outDir: v.string().optional(),
target: v.literal("browser"),
plugins: v.custom((value) => typeof value === "function"),
plugins: v.optional(v.custom((value) => typeof value === "function")),

// plugins: v.special((value) => typeof value === "function"),
}),
});
Expand Down
2 changes: 1 addition & 1 deletion packages/vinxi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vinxi",
"version": "0.0.7",
"version": "0.0.8",
"type": "module",
"author": "Nikhil Saraf <[email protected]>",
"files": [
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

42 changes: 16 additions & 26 deletions test/templates/react/app/entry-server.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
/// <reference types="vinxi/server" />
import { renderAsset } from "@vinxi/react";
import React, { Suspense } from "react";
import { renderToPipeableStream } from "react-dom/server";
import { eventHandler } from "vinxi/runtime/server";

import { renderAsset } from "./render-asset";
import App from "./root";

export default eventHandler(async (event) => {
const clientManifest = import.meta.env.MANIFEST["client"];
const assets = await clientManifest.inputs[clientManifest.handler].assets();

function Assets() {
return <>{assets.map((asset) => renderAsset(asset))}</>;
}

const events = {};
const stream = renderToPipeableStream(
<App
assets={
<Suspense>
<Assets />
</Suspense>
}
/>,
{
onAllReady: () => {
events["end"]?.();
const stream = await new Promise(async (resolve) => {
const stream = renderToPipeableStream(
<App assets={<Suspense>{assets.map((m) => renderAsset(m))}</Suspense>} />,
{
onShellReady() {
resolve(stream);
},
bootstrapModules: [
clientManifest.inputs[clientManifest.handler].output.path,
],
bootstrapScriptContent: `window.manifest = ${JSON.stringify(
await clientManifest.json(),
)}`,
},
bootstrapModules: [
clientManifest.inputs[clientManifest.handler].output.path,
],
bootstrapScriptContent: `window.manifest = ${JSON.stringify(
await clientManifest.json(),
)}`,
},
);
);
});

// @ts-ignore
stream.on = (event, listener) => {
events[event] = listener;
};

event.node.res.setHeader("Content-Type", "text/html");

return stream;
});
1 change: 1 addition & 0 deletions test/templates/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"start": "node .output/server/index.mjs"
},
"dependencies": {
"@vinxi/react": "workspace:^",
"@vitejs/plugin-react": "^4.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down

0 comments on commit 26f2f10

Please sign in to comment.