Skip to content

Commit

Permalink
chore: update version to 0.2.1 and refactor HTML rendering logic in b…
Browse files Browse the repository at this point in the history
…uild script
  • Loading branch information
actualwitch committed Dec 16, 2024
1 parent f735a6b commit 57c8903
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "🔬 Experiment is a simple tool to facilitate prompt engineering.",
"keywords": ["inference", "experiment-tracking", "llm"],
"repository": "github:actualwitch/experiment",
"version": "0.2.0",
"version": "0.2.1",
"author": "Ade あで Fisher",
"license": "MIT",
"private": true,
Expand Down
23 changes: 8 additions & 15 deletions scripts/build.spa.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { $ } from "bun";
import { renderToString } from "react-dom/server";
import { StaticRouter } from "react-router";
import { Shell } from "../src/root";
import { getHtml } from "../src/entry/_handlers";
import { assignToWindow } from "../src/utils/hydration";

// why does this work but running it from Bun.build fails? #justbunthings
Expand All @@ -14,18 +12,13 @@ await $`bun build ./src/entry/client.tsx --outdir ./spa`;
// throw new AggregateError(buildResult.logs, "Build failed");
// }

const html = getHtml(
`${process.env.BASE_URL ?? ""}/`,
[assignToWindow("REALM", `"SPA"`), process.env.BASE_URL && assignToWindow("BASE_URL", `"${process.env.BASE_URL}"`)],
process.env.BASE_URL,
);

await Bun.write(
"./spa/index.html",
renderToString(
<StaticRouter location={`${process.env.BASE_URL ?? ""}/`} basename={process.env.BASE_URL}>
<Shell
bootstrap
baseUrl={process.env.BASE_URL}
additionalScripts={[
assignToWindow("REALM", `"SPA"`),
process.env.BASE_URL && assignToWindow("BASE_URL", `"${process.env.BASE_URL}"`),
]}
/>
</StaticRouter>,
),
html,
);
6 changes: 3 additions & 3 deletions src/entry/_handlers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { publish, subscribe, type Update } from "../state/æther";
import { eventStream } from "../utils/eventStream";
import { getClientAsString } from "./_macro" with { type: "macro" };

export const getHtml = (location: string, additionalScripts?: string[]) => {
export const getHtml = (location: string, additionalScripts?: string[], baseUrl?: string) => {
const html = renderToString(
<StaticRouter location={location}>
<Shell bootstrap additionalScripts={additionalScripts} />
<StaticRouter location={location} basename={baseUrl}>
<Shell bootstrap additionalScripts={additionalScripts} baseUrl={baseUrl} />
</StaticRouter>,
);
return `<!DOCTYPE html>${html}`;
Expand Down
2 changes: 1 addition & 1 deletion src/state/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,5 @@ export const parentAtom = entangledAtom("parent", atom<string | undefined>(undef

export const rendererModeAtom = entangledAtom(
"rendererMode",
focusAtom(storeAtom, (o) => o.prop("rendererMode")),
focusAtom(storeAtom, (o) => o.prop("rendererMode").valueOr("markdown")),
);

0 comments on commit 57c8903

Please sign in to comment.