Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .github/workflows/prerelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish web-fragments
run: pnpm publish --no-git-checks --tag dev --access public
working-directory: packages/web-fragments
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish vite
run: pnpm publish --no-git-checks --tag dev --access public
working-directory: packages/vite
Expand Down Expand Up @@ -69,10 +75,10 @@ jobs:

Install the prerelease packages with:
\`\`\`bash
npm install @orange-js/orange@0.0.0-${sha} @orange-js/actors@0.0.0-${sha} && npm install -D @orange-js/vite@0.0.0-${sha} @orange-js/cli@0.0.0-${sha}
pnpm add @orange-js/orange@0.0.0-${sha} @orange-js/actors@0.0.0-${sha} && pnpm add -D @orange-js/vite@0.0.0-${sha} @orange-js/cli@0.0.0-${sha}
yarn add @orange-js/orange@0.0.0-${sha} @orange-js/actors@0.0.0-${sha} && yarn add -D @orange-js/vite@0.0.0-${sha} @orange-js/cli@0.0.0-${sha}
bun add @orange-js/orange@0.0.0-${sha} @orange-js/actors@0.0.0-${sha} && bun add -D @orange-js/vite@0.0.0-${sha} @orange-js/cli@0.0.0-${sha}
npm install @orange-js/orange@0.0.0-${sha} @orange-js/actors@0.0.0-${sha} @orange-js/web-fragments@0.0.0-${sha} && npm install -D @orange-js/vite@0.0.0-${sha} @orange-js/cli@0.0.0-${sha}
pnpm add @orange-js/orange@0.0.0-${sha} @orange-js/actors@0.0.0-${sha} @orange-js/web-fragments@0.0.0-${sha} && pnpm add -D @orange-js/vite@0.0.0-${sha} @orange-js/cli@0.0.0-${sha}
yarn add @orange-js/orange@0.0.0-${sha} @orange-js/actors@0.0.0-${sha} @orange-js/web-fragments@0.0.0-${sha} && yarn add -D @orange-js/vite@0.0.0-${sha} @orange-js/cli@0.0.0-${sha}
bun add @orange-js/orange@0.0.0-${sha} @orange-js/actors@0.0.0-${sha} @orange-js/web-fragments@0.0.0-${sha} && bun add -D @orange-js/vite@0.0.0-${sha} @orange-js/cli@0.0.0-${sha}
\`\`\``;

github.rest.issues.createComment({
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish web-fragments
run: pnpm publish
working-directory: packages/web-fragments
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish vite
run: pnpm publish
working-directory: packages/vite
Expand Down
4 changes: 4 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
"./hono": {
"import": "./dist/hono.js",
"types": "./dist/hono.d.ts"
},
"./rsc": {
"import": "./dist/rsc.js",
"types": "./dist/rsc.d.ts"
}
},
"optionalDependencies": {
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/rsc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ErrorInfo } from "react";
import { renderHtml } from "./server.js";

export * from "@vitejs/plugin-rsc/rsc";

export async function renderServerComponentStreamToHtmlReadableStream(
stream: ReadableStream<Uint8Array>,
options?: {
onError?: (error: unknown, errorInfo: ErrorInfo) => void;
}
) {
return await renderHtml(stream, options);
}
16 changes: 11 additions & 5 deletions packages/core/src/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,7 @@ async function rscResponse({
});
}

const { renderHTML } = await import.meta.viteRsc.loadModule<
typeof import("./ssr.js")
>("ssr", "index");

const htmlStream = await renderHTML(rscStream, {
const htmlStream = await renderHtml(rscStream, {
formState,
// allow quick simulation of javscript disabled browser
debugNojs: url.searchParams.has("__nojs"),
Expand All @@ -186,6 +182,16 @@ const wsPattern = new URLPattern({
pathname: "/:actor/:id",
});

type RenderHtml = typeof import("./ssr.js").renderHTML;

export const renderHtml: RenderHtml = async (stream, options) => {
const { renderHTML } = await import.meta.viteRsc.loadModule<
typeof import("./ssr.js")
>("ssr", "index");

return renderHTML(stream, options);
};

export function app(Layout: Layout, options?: AppOptions) {
return {
async fetch(request: Request) {
Expand Down
30 changes: 30 additions & 0 deletions packages/web-fragments/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@orange-js/web-fragments",
"version": "0.3.0",
"description": "",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"build": "tsc",
"build:watch": "tsc -w"
},
"devDependencies": {
"@types/react": "^19.1.8",
"react": "^19.1.1",
"typescript": "^5.7.2"
},
"keywords": [],
"author": "",
"license": "ISC",
"packageManager": "pnpm@10.13.1",
"peerDependencies": {
"react": "^19.1.1"
}
}
46 changes: 46 additions & 0 deletions packages/web-fragments/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from "react";
import { app as orangeApp } from "@orange-js/orange/server";
import { routes } from "virtual:orange/routes";
import {
renderToReadableStream,
renderServerComponentStreamToHtmlReadableStream,
} from "@orange-js/orange/rsc";

export const app: typeof orangeApp = (Layout, options) => {
const { fetch } = orangeApp(Layout, options);
return {
fetch: async (request: Request) => {
if (request.url.includes("/__web-fragments")) {
if ("__webFragmentsHandler" in globalThis) {
// @ts-ignore
return await globalThis.__webFragmentsHandler(request);
}

const fallbacks: Record<string, string> = {};

for (const route of routes) {
if ("FragmentFallback" in route.module) {
const stream = renderToReadableStream({
root: (
<Layout>
{/* @ts-ignore */}
<route.module.FragmentFallback />
</Layout>
),
});

const htmlStream =
await renderServerComponentStreamToHtmlReadableStream(stream);
const html = await new Response(htmlStream).text();

fallbacks[route.pattern.pathname] = html;
}
}

return Response.json(fallbacks);
}

return await fetch(request);
},
};
};
13 changes: 13 additions & 0 deletions packages/web-fragments/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": [
"vite/client",
"@vitejs/plugin-rsc/types",
"@cloudflare/workers-types",
"@types/node",
"@orange-js/orange/modules"
],
"outDir": "dist"
}
}
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion scripts/version-for-prerelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ for (const pkg of pkgs) {
pkgJson.version = `0.0.0-${commitHash}`;

fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
}
}