Skip to content
Merged
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
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,14 @@
</head>
<body>
<script>
// Apply the shared preference before the prerendered landing page paints.
// Apply saved preferences before the prerendered page paints.
(() => {
let theme;
try {
theme = window.localStorage.getItem("weblua:theme");
if (window.localStorage.getItem("weblua:about-dismissed")) {
document.body.dataset.aboutDismissed = "";
}
} catch {}
if (theme !== "dark" && theme !== "light") {
theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
Expand Down
65 changes: 38 additions & 27 deletions scripts/postbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// 2. Emits dist/playground/index.html and dist/embed/index.html with
// route-specific <title>/description/canonical tags (nginx's
// `try_files $uri $uri/index.html` picks them up), instead of every route claiming
// to be the homepage. The embed route is marked noindex.
// to be the homepage. The embed route is marked noindex. The playground
// route also gets its prerendered shell: header, <h1>, and about text.
// 3. Adds a modulepreload for the lazily-imported playground chunk to the app
// routes, so splitting it out of the landing bundle doesn't cost
// /playground an extra round trip.
Expand Down Expand Up @@ -40,7 +41,7 @@ function replaceOnce(html, pattern, replacement, label) {
return next;
}

function routeHtml({ title, description, canonical, noindex }) {
function routeHtml({ title, description, canonical, noindex, markup }) {
let html = replaceOnce(
template,
"</head>",
Expand Down Expand Up @@ -77,17 +78,43 @@ function routeHtml({ title, description, canonical, noindex }) {
"canonical (noindex insert)"
);
}
if (markup) {
html = replaceOnce(html, '<div id="root"></div>', `<div id="root">${markup}</div>`, '<div id="root">');
}
return html;
}

const server = await createServer({
configFile: path.join(repoRoot, "vite.config.ts"),
server: { middlewareMode: true },
appType: "custom",
logLevel: "error"
});

let landingMarkup;
let playgroundMarkup;
try {
const { renderLanding, renderPlaygroundShell } = await server.ssrLoadModule("/src/entry-prerender.tsx");
landingMarkup = renderLanding();
playgroundMarkup = renderPlaygroundShell();
} finally {
await server.close();
}
for (const [label, markup] of [["landing", landingMarkup], ["playground", playgroundMarkup]]) {
if (!markup.includes("<h1")) {
throw new Error(`postbuild: prerendered ${label} markup is missing its <h1>`);
}
}

const routes = [
{
dir: "playground",
title: "Online Luau &amp; Lua Editor — Weblua Playground",
description:
"Write, run, type-check, and share multi-file Luau and Lua 5.1–5.5 projects in your browser. Switch runtimes instantly; no account or install needed.",
canonical: "https://weblua.com/playground",
noindex: false
noindex: false,
markup: playgroundMarkup
},
{
dir: "embed",
Expand All @@ -105,27 +132,11 @@ for (const route of routes) {
console.log(`postbuild: wrote dist/${route.dir}/index.html`);
}

const server = await createServer({
configFile: path.join(repoRoot, "vite.config.ts"),
server: { middlewareMode: true },
appType: "custom",
logLevel: "error"
});

try {
const { renderLanding } = await server.ssrLoadModule("/src/entry-prerender.tsx");
const markup = renderLanding();
if (!markup.includes("<h1")) {
throw new Error("postbuild: prerendered landing markup is missing its <h1>");
}
const prerendered = replaceOnce(
template,
'<div id="root"></div>',
`<div id="root">${markup}</div>`,
'<div id="root">'
);
writeFileSync(path.join(dist, "index.html"), prerendered);
console.log(`postbuild: prerendered landing into dist/index.html (${(markup.length / 1024).toFixed(1)} kB of markup)`);
} finally {
await server.close();
}
const prerendered = replaceOnce(
template,
'<div id="root"></div>',
`<div id="root">${landingMarkup}</div>`,
'<div id="root">'
);
writeFileSync(path.join(dist, "index.html"), prerendered);
console.log(`postbuild: prerendered landing into dist/index.html (${(landingMarkup.length / 1024).toFixed(1)} kB of markup)`);
5 changes: 4 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Suspense, lazy, useEffect, useMemo } from "react";
import { Landing } from "./components/Landing";
import { PlaygroundShell } from "./components/PlaygroundShell";
import { getAppRoute } from "./lib/routes";
import { useTheme } from "./lib/theme";

Expand Down Expand Up @@ -37,8 +38,10 @@ export function App() {
return <Landing theme={theme} onToggleTheme={toggleTheme} />;
}

// The fallback matches the shell prerendered into /playground's HTML, so the
// header and about text stay put while the editor chunk loads.
return (
<Suspense fallback={<div className={isEmbed ? "app app-embed" : "app"} />}>
<Suspense fallback={<PlaygroundShell theme={theme} onToggleTheme={toggleTheme} isEmbed={isEmbed} />}>
<Playground theme={theme} onToggleTheme={toggleTheme} isEmbed={isEmbed} />
</Suspense>
);
Expand Down
42 changes: 4 additions & 38 deletions src/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,22 @@ import {
FilePlus2,
FolderOpen,
Link,
Moon,
Pencil,
Play,
Plus,
RotateCcw,
Save,
ShieldCheck,
Square,
Sun,
Timer,
Trash2,
Upload,
WandSparkles,
X
} from "lucide-react";
import { type ChangeEvent, type UIEvent, useCallback, useEffect, useMemo, useRef, useState } from "react";
import { GitHubMark, MoonMark } from "./components/Brand";
import { GitHubMark } from "./components/Brand";
import { PlaygroundShell } from "./components/PlaygroundShell";
import { SwapLabel } from "./components/SwapLabel";
import { luaSupport, refreshLuaContext } from "./lang/lua";
import { checkProject } from "./lib/checker";
Expand Down Expand Up @@ -980,38 +979,7 @@ export default function Playground({ theme, onToggleTheme, isEmbed }: Playground
const activeNamedProject = projects.find((project) => project.id === workspace.activeProjectId);

return (
<div className={isEmbed ? "app app-embed" : "app"}>
{!isEmbed && (
<header className="app-header">
<a className="brand" href="/" aria-label="Weblua home">
<MoonMark size={26} />
<h1>Weblua</h1>
<span className="brand-tag">Playground</span>
</a>
<div className="header-actions">
<a
className="icon-button"
href="https://github.com/PytechNo/Weblua"
target="_blank"
rel="noreferrer"
title="Open GitHub repository"
aria-label="Open GitHub repository"
>
<GitHubMark size={17} />
</a>
<button
className="icon-button"
type="button"
onClick={onToggleTheme}
title={theme === "dark" ? "Use light theme" : "Use dark theme"}
aria-label={theme === "dark" ? "Use light theme" : "Use dark theme"}
>
{theme === "dark" ? <Sun size={17} /> : <Moon size={17} />}
</button>
</div>
</header>
)}

<PlaygroundShell theme={theme} onToggleTheme={onToggleTheme} isEmbed={isEmbed}>
<main className="workspace">
<div className="toolbar" aria-label="Playground controls">
<label className="control">
Expand Down Expand Up @@ -1321,9 +1289,7 @@ export default function Playground({ theme, onToggleTheme, isEmbed }: Playground
</aside>
</div>
</main>

{!isEmbed && <footer className="seo-line">Weblua runs Lua and Luau projects entirely in your browser. Named projects, draft recovery, and shared source never require an account.</footer>}
</div>
</PlaygroundShell>
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ export function Landing({ theme, onToggleTheme }: LandingProps) {
<div className="section-head reveal">
<span className="eyebrow">How it works</span>
<h2 id="how-title">
Three steps. <span className="grad-text">Zero setup.</span>
How to run <span className="grad-text">Luau online</span>
</h2>
</div>
<ol className="steps">
Expand Down Expand Up @@ -889,9 +889,9 @@ export function Landing({ theme, onToggleTheme }: LandingProps) {
{/* ---------- FAQ ---------- */}
<section className="section section-narrow" id="faq" aria-labelledby="faq-title">
<div className="section-head reveal">
<span className="eyebrow">FAQ</span>
<span className="eyebrow">Questions</span>
<h2 id="faq-title">
Questions, <span className="grad-text">answered</span>
Luau &amp; Lua playground <span className="grad-text">FAQ</span>
</h2>
</div>
<div className="faq-list">
Expand Down
103 changes: 103 additions & 0 deletions src/components/PlaygroundShell.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { Moon, Sun, X } from "lucide-react";
import type { ReactNode } from "react";
import type { Theme } from "../lib/theme";
import { GitHubMark, MoonMark } from "./Brand";

/** Read by index.html's pre-paint script, which hides the card on later visits. */
const ABOUT_DISMISSED_KEY = "weblua:about-dismissed";

function dismissAbout() {
document.body.dataset.aboutDismissed = "";
try {
window.localStorage.setItem(ABOUT_DISMISSED_KEY, "1");
} catch {
// Still hidden for this visit when browser storage is unavailable.
}
}

interface PlaygroundShellProps {
theme: Theme;
onToggleTheme: () => void;
isEmbed: boolean;
/** The workspace; an empty one holds its space while the editor chunk loads. */
children?: ReactNode;
}

/**
* The playground's page frame: the header with the page's <h1>, and the about
* text, a dismissible card on desktop. It stays out of Playground.tsx so the build can
* prerender it into dist/playground/index.html for crawlers that don't run JS,
* and so App's Suspense fallback paints the same markup until the editor loads.
*/
export function PlaygroundShell({ theme, onToggleTheme, isEmbed, children }: PlaygroundShellProps) {
return (
<div className={isEmbed ? "app app-embed" : "app"}>
{!isEmbed && (
<header className="app-header">
<div className="app-heading">
<a className="brand" href="/" aria-label="Weblua home">
<MoonMark size={26} />
<span className="brand-name">Weblua</span>
</a>
<h1 className="app-title">Online Luau &amp; Lua Editor</h1>
</div>
<div className="header-actions">
<a
className="icon-button"
href="https://github.com/PytechNo/Weblua"
target="_blank"
rel="noreferrer"
title="Open GitHub repository"
aria-label="Open GitHub repository"
>
<GitHubMark size={17} />
</a>
<button
className="icon-button"
type="button"
onClick={onToggleTheme}
title={theme === "dark" ? "Use light theme" : "Use dark theme"}
aria-label={theme === "dark" ? "Use light theme" : "Use dark theme"}
>
{theme === "dark" ? <Sun size={17} /> : <Moon size={17} />}
</button>
</div>
</header>
)}

{children ?? <main className="workspace" />}

{!isEmbed && (
<section className="playground-about" aria-labelledby="playground-about-title">
<h2 id="playground-about-title">Online Luau compiler and Lua interpreter</h2>
<p>
Weblua is a free online Luau and Lua editor. Pick a runtime, Luau or Lua 5.1, 5.2, 5.3,
5.4, or 5.5, and press Run. Each run happens in a Web Worker in your browser through
WebAssembly, so there is no execution server, nothing to install, and no account.
</p>
<p>
The editor runs Luau's type checker as you type, in strict or nonstrict mode, and the
Bytecode tab shows what the Luau compiler emits at optimization levels 0 to 2. Projects
can span several files linked with require, read preset input, and be formatted with
StyLua.
</p>
<p>
Share a project as a link or an iframe embed, or open one from a GitHub gist. Named
projects stay in this browser. Weblua runs the Luau language, not Roblox, so Roblox
services and instances aren't available. More in the{" "}
<a href="/#faq">Luau &amp; Lua playground FAQ</a>.
</p>
<button
className="icon-button playground-about-close"
type="button"
onClick={dismissAbout}
title="Dismiss"
aria-label="Dismiss about Weblua"
>
<X size={16} />
</button>
</section>
)}
</div>
);
}
9 changes: 9 additions & 0 deletions src/entry-prerender.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { renderToStaticMarkup } from "react-dom/server";
import { Landing } from "./components/Landing";
import { PlaygroundShell } from "./components/PlaygroundShell";

/**
* Build-time entry used by scripts/postbuild.mjs to bake the landing page
Expand All @@ -9,3 +10,11 @@ import { Landing } from "./components/Landing";
export function renderLanding(): string {
return renderToStaticMarkup(<Landing theme="dark" onToggleTheme={() => {}} />);
}

/**
* The playground's header, <h1>, and about text around an empty workspace,
* for dist/playground/index.html. The editor itself only renders client-side.
*/
export function renderPlaygroundShell(): string {
return renderToStaticMarkup(<PlaygroundShell theme="dark" onToggleTheme={() => {}} isEmbed={false} />);
}
Loading
Loading