Skip to content

Commit

Permalink
refactor client server components to references plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nksaraf committed Aug 15, 2023
1 parent c7bc296 commit f1f8f82
Show file tree
Hide file tree
Showing 24 changed files with 896 additions and 1,359 deletions.
486 changes: 18 additions & 468 deletions examples/react/rsc/spa/app.config.js

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions examples/react/rsc/spa/app/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import React, { Suspense, startTransition } from "react";
import { Root, createRoot, hydrateRoot } from "react-dom/client";
import "vinxi/runtime/client";

import { sayHello } from "./actions";
import { fetchServerAction } from "./fetchServerAction";
import { ServerComponent } from "./server-component";

// document.addEventListener("click", async (e) => {
// console.log(sayHello, "hello");
document.addEventListener("click", async (e) => {
console.log(sayHello, "hello");

// const result = await fetchServerAction("/_server", sayHello["$$id"], []);
// console.log(result);
// // sayHello();
// });
const result = await fetchServerAction("/_server", sayHello["$$id"], []);
console.log(result);
// sayHello();
});

globalThis.__vite__ = createModuleLoader({
loadModule: async (id) => {
Expand Down
5 changes: 3 additions & 2 deletions examples/react/rsc/spa/app/react-server.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { renderAsset } from "@vinxi/react";
import { renderToPipeableStream } from "@vinxi/react-server-dom-vite/server";
import React, { Suspense } from "react";
import { eventHandler, sendStream } from "vinxi/runtime/server";
import { Suspense } from "react";
import { eventHandler } from "vinxi/runtime/server";

import App from "./app";

Expand All @@ -28,6 +28,7 @@ export default eventHandler(async (event) => {
decodeReplyFromBusboy,
decodeAction,
} = await import("@vinxi/react-server-dom-vite/server");
console.log(event.node.req.headers);
const serverReference = event.node.req.headers["rsc-action"];
if (serverReference) {
// This is the client-side case
Expand Down
1 change: 1 addition & 0 deletions examples/react/rsc/spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"dependencies": {
"@picocss/pico": "^1.5.7",
"@vinxi/plugin-references": "workspace:^",
"@vinxi/react": "workspace:^",
"@vinxi/react-server-dom-vite": "^0.0.2",
"@vitejs/plugin-react": "^4.0.1",
Expand Down
Loading

0 comments on commit f1f8f82

Please sign in to comment.