Skip to content

Commit

Permalink
fix tests (doesnt work well in local)
Browse files Browse the repository at this point in the history
  • Loading branch information
nksaraf committed Sep 25, 2023
1 parent 66c07a2 commit 416239a
Show file tree
Hide file tree
Showing 13 changed files with 11 additions and 162 deletions.
1 change: 0 additions & 1 deletion frameworks/solid-start/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import solid from "vite-plugin-solid";

class SolidStartFileSystemRouter extends BaseFileSystemRouter {
toPath(src) {
console.log(src);
const routePath = cleanPath(src, this.config)
// remove the initial slash
.slice(1)
Expand Down
2 changes: 0 additions & 2 deletions frameworks/solid-start/root/routes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import fileRoutes, { RouteModule } from "vinxi/routes";

console.log("fileRoutes", fileRoutes);

const defineRoutes = (fileRoutes: RouteModule[]) => {
function processRoute(routes, route, id, full) {
const parentRoute = Object.values(routes).find((o) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/vinxi-react-server/server-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export default eventHandler(async (event) => {
event.node.res.setHeader("Router", "server");

return stream;
} catch (x) {
console.log("errorr", x);
} catch (error) {
console.error("error during server action", error);
// We handle the error on the client
}
// Refresh the client and return the value
Expand Down
1 change: 0 additions & 1 deletion packages/vinxi/lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export function createApp({
router.mode in routerSchema,
`Invalid router mode ${router.mode}`,
);
console.log(router);
const result = routerSchema[router.mode].safeParse(router);
if (result.success !== true) {
const issues = result.error.issues.map((issue) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/vinxi/lib/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export async function createViteServer(config) {
* @returns {Promise<import("vite").ViteDevServer>}
*/
export async function createViteHandler(router, app, serveConfig) {
const port = await getPort({ port: 9000 + router.order * 10 });
const viteDevServer = await createViteServer({
configFile: false,
base: router.base,
Expand All @@ -60,7 +61,7 @@ export async function createViteHandler(router, app, serveConfig) {
server: {
middlewareMode: true,
hmr: {
port: await getPort({ port: serveConfig.ws.port + router.order }),
port,
},
},
});
Expand All @@ -84,7 +85,7 @@ export async function createDevServer(
port,
dev,
ws: {
port: wsPort ?? 8989,
port: wsPort,
},
};

Expand Down
1 change: 0 additions & 1 deletion packages/vinxi/lib/plugins/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export function routes() {
) {
const js = jsCode();
const routes = await router.internals.routes?.getRoutes();
console.log(routes);

let routesCode = JSON.stringify(routes ?? [], (k, v) => {
if (!v) {
Expand Down
1 change: 0 additions & 1 deletion test/templates/react-rsc/app/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

let store = { count: 0 };
export function sayHello() {
console.log("Hello World");
store.count++;
return store.count;
}
Expand Down
35 changes: 3 additions & 32 deletions test/templates/react-rsc/app/react-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,21 @@ import { eventHandler } from "vinxi/server";
import App from "./app";

export default eventHandler(async (event) => {
console.log("event", event);
async function loadModule(id) {
if (import.meta.env.DEV) {
console.log(import.meta.env.MANIFEST["rsc"].chunks[id].output.path);
return await import(
import.meta.env.MANIFEST["rsc"].chunks[id].output.path
);
}

console.log(id, globalThis.$$chunks);
if (globalThis.$$chunks[id + ".js"]) {
return globalThis.$$chunks[id + ".js"];
}
return await import(import.meta.env.MANIFEST["rsc"].chunks[id].output.path);
}
if (event.node.req.method === "POST") {
const {
renderToPipeableStream,
decodeReply,
decodeReplyFromBusboy,
decodeAction,
} = await import("@vinxi/react-server-dom/server");
console.log(event.node.req.headers);
const serverReference = event.node.req.headers["server-action"];
if (event.method === "POST") {
const { decodeReply } = await import("@vinxi/react-server-dom/server");
const serverReference = event.headers.get("server-action");
if (serverReference) {
// This is the client-side case
const [filepath, name] = serverReference.split("#");
Expand All @@ -42,27 +33,17 @@ export default eventHandler(async (event) => {
}

let args;
// if (req.is('multipart/form-data')) {
// // Use busboy to streamingly parse the reply from form-data.
// const bb = busboy({headers: req.headers});
// const reply = decodeReplyFromBusboy(bb, moduleBasePath);
// req.pipe(bb);
// args = await reply;
// } else {
const text = await new Promise((resolve) => {
const requestBody = [];
event.node.req.on("data", (chunks) => {
console.log(chunks);
requestBody.push(chunks);
});
event.node.req.on("end", () => {
resolve(requestBody.join(""));
});
});
console.log(text);

args = await decodeReply(text);
console.log(args, action);
// }
const result = action.apply(null, args);
try {
Expand All @@ -77,15 +58,13 @@ export default eventHandler(async (event) => {
throw new Error("Invalid request");
}
}
console.log("rendering");
const reactServerManifest = import.meta.env.MANIFEST["rsc"];
const serverAssets = await reactServerManifest.inputs[
reactServerManifest.handler
].assets();
const clientManifest = import.meta.env.MANIFEST["client"];
const assets = await clientManifest.inputs[clientManifest.handler].assets();

const events = {};
const stream = renderToPipeableStream(
<App
assets={
Expand All @@ -97,15 +76,7 @@ export default eventHandler(async (event) => {
/>,
);

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

event.node.res.setHeader("Content-Type", "text/x-component");
event.node.res.setHeader("Router", "rsc");

return stream;
});
52 changes: 0 additions & 52 deletions test/templates/react-rsc/app/server-action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ import { eventHandler, sendStream } from "vinxi/server";
// import App from "./app";

export default eventHandler(async (event) => {
console.log("event", event);
async function loadModule(id) {
if (import.meta.env.DEV) {
console.log(import.meta.env.MANIFEST["rsc"].chunks[id].output.path);
return await import(
import.meta.env.MANIFEST["rsc"].chunks[id].output.path
);
}

console.log(id, globalThis.$$chunks);
if (globalThis.$$chunks[id + ".js"]) {
return globalThis.$$chunks[id + ".js"];
}
Expand All @@ -41,42 +38,24 @@ export default eventHandler(async (event) => {
}

let args;
// if (req.is('multipart/form-data')) {
// // Use busboy to streamingly parse the reply from form-data.
// const bb = busboy({headers: req.headers});
// const reply = decodeReplyFromBusboy(bb, moduleBasePath);
// req.pipe(bb);
// args = await reply;
// } else {
const text = await new Promise((resolve) => {
const requestBody = [];
event.node.req.on("data", (chunks) => {
console.log(chunks);
requestBody.push(chunks);
});
event.node.req.on("end", () => {
resolve(requestBody.join(""));
});
});
console.log(text);

args = await decodeReply(text);
console.log(args, action);
// }
const result = action.apply(null, args);
try {
// Wait for any mutations
await result;
const events = {};
const stream = renderToPipeableStream(result);

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

event.node.res.setHeader("Content-Type", "application/json");
event.node.res.setHeader("Router", "server");

Expand All @@ -90,35 +69,4 @@ export default eventHandler(async (event) => {
throw new Error("Invalid request");
}
}
console.log("rendering");
// const reactServerManifest = import.meta.env.MANIFEST["rsc"];
// const serverAssets = await reactServerManifest.inputs[
// reactServerManifest.handler
// ].assets();
// const clientManifest = import.meta.env.MANIFEST["client"];
// const assets = await clientManifest.inputs[clientManifest.handler].assets();

// const events = {};
// const stream = renderToPipeableStream(
// <App
// assets={
// <Suspense>
// {serverAssets.map((m) => renderAsset(m))}
// {assets.map((m) => renderAsset(m))}
// </Suspense>
// }
// />,
// );

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

// event.node.res.setHeader("Content-Type", "text/x-component");
// event.node.res.setHeader("Router", "rsc");

// return result;
});
64 changes: 3 additions & 61 deletions test/templates/react-rsc/app/server.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
/// <reference types="vinxi/types/server" />
import viteServer from "#vite-dev-server";
import { renderAsset } from "@vinxi/react";
import * as ReactServerDOM from "@vinxi/react-server-dom/client";
import { createModuleLoader } from "@vinxi/react-server-dom/runtime";
import React, { Suspense } from "react";
import { renderToPipeableStream } from "react-dom/server";
import { H3Event, eventHandler, fetchWithEvent } from "vinxi/server";
import { H3Event, eventHandler, setHeader } from "vinxi/server";

import { Readable, Writable } from "node:stream";

import App from "./app";

export default eventHandler(async (event) => {
globalThis.__vite__ = createModuleLoader(viteServer);

Expand All @@ -22,23 +18,13 @@ export default eventHandler(async (event) => {

const writableStream = new Writable({
write(chunk, encoding, callback) {
console.log("chunk", chunk);

readable.push(chunk);
callback();
},
});
writableStream.setHeader = () => {};

writableStream.on("finish", () => {
// parentPort?.postMessage(
// JSON.stringify({
// chunk: "end",
// id: rest.id,
// })
// );
console.log("finish");

readable.push(null);
readable.destroy();
});
Expand All @@ -49,59 +35,15 @@ export default eventHandler(async (event) => {

const clientManifest = import.meta.env.MANIFEST["client"];

const events = {};
console.log("element", "here");

const element = await ReactServerDOM.createFromNodeStream(readable);

console.log("element", element);

const stream = renderToPipeableStream(element, {
bootstrapModules: [
clientManifest?.inputs[clientManifest.handler].output.path,
].filter(Boolean) as string[],
bootstrapScriptContent: `
window.base = "${import.meta.env.BASE_URL}";`,
// {
// onAllReady: () => {
// events["end"]?.();
// },
// bootstrapModules: [
// clientManifest.inputs[clientManifest.handler].output.path,
// ],
// bootstrapScriptContent: `window.manifest = ${JSON.stringify(
// await clientManifest.json(),
// )}`,
// },
bootstrapScriptContent: `window.base = "${import.meta.env.BASE_URL}";`,
});

// 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"]?.();
// },
// bootstrapModules: [
// clientManifest.inputs[clientManifest.handler].output.path,
// ],
// bootstrapScriptContent: `window.manifest = ${JSON.stringify(
// await clientManifest.json(),
// )}`,
// },
// );

// @ts-ignore
stream.on = (event, listener) => {
console.log("on", "event", event);

events[event] = listener;
};

console.log("render");

event.node.res.setHeader("Content-Type", "text/html");
setHeader(event, "Content-Type", "text/html");
return stream;
});
1 change: 0 additions & 1 deletion test/templates/react-rsc/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { eventHandler, toWebRequest } from "vinxi/server";

export default eventHandler((event) => {
console.log(toWebRequest(event));
return new Response(
`
<!DOCTYPE html>
Expand Down
4 changes: 0 additions & 4 deletions test/templates/react-ssr-fs/app/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ export default eventHandler(async (event) => {
const clientManifest = import.meta.env.MANIFEST["client"];
const serverManifest = import.meta.env.MANIFEST["ssr"];

console.log(fileRoutes);

const routes = fileRoutes.map((route) => {
return {
...route,
component: lazyRoute(route.$component, clientManifest, serverManifest),
};
});

console.log(routes);

const assets = await clientManifest.inputs[clientManifest.handler].assets();
const events = {};

Expand Down
Loading

0 comments on commit 416239a

Please sign in to comment.