Skip to content

Add a playground that shows .rx as Solid 2.0 primitives - #70

Open
brenelz wants to merge 17 commits into
solidjs:mainfrom
brenelz:playground-wasm-app
Open

brenelz wants to merge 17 commits into
solidjs:mainfrom
brenelz:playground-wasm-app

Conversation

@brenelz

@brenelz brenelz commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

A browser playground for learning what ReactiveScript compiles to: type .rx on the left, and the right side shows the same program written with Solid 2.0's own primitives (createSignal, createMemo, createOptimistic, createProjection, action, <Errored>, <Loading>), with the checker's diagnostics underneath. Work in progress; it is not deployed.

The playground: .rx on the left, the same program as Solid 2.0 primitives on the right

Compiler change

The language server's WebAssembly build (src/wasm.rs) already answers analyze and prelude over a host rx_read, so it can run from memory in a browser. It could not compile, because app::app reads the program from disk. Two small changes make it possible:

  • app::app_with takes a reader in place of the disk; app::app (the Node-API build and rxc app) calls it with read_disk and behaves as before.
  • serve.rs answers an app request ({entry, overlays, target, moduleName, spa, jsx}) through it. With jsx: true, each module also carries the JSX handed to Solid's compiler, printed by the new emit::view_jsx over oxc_codegen (already in the lockfile through solidjs-compiler, now a direct dependency).
  • analyze takes project: false to return diagnostics without building the TSX projection, which the playground does not show. Leaving it out keeps the language server's behaviour.

The playground also turned up a parser bug that the language server shares: the recovering parse read a missing statement as an empty one without advancing, so parse_block spun on an unclosed { at the end of input. A half-typed handler such as onClick={() => { c made analyze take 8 to 27 seconds. parse_block now stops when a pass reads nothing, and the missing } is an ordinary parse error.

The napi wasm32-wasi browser build was the other candidate, but its WASI has no filesystem, so app(entry) cannot read sources there.

Playground (site/playground/)

A Vite + Solid 2.0.3 app. Each keystroke runs analyze (with project: false) for diagnostics and app with jsx: true for the program, under 1 ms per keystroke once the compiler is warm. The page renders before rxc.wasm arrives; the wasm is built with symbols stripped (4.8 MB), compiled while it streams, and retried if the download is cut off. The JSX is formatted with Prettier, then src/solidify.ts writes each __rt helper that is a Solid primitive underneath (spec/11 CP-4b, @reactivescript/runtime) as that primitive and strips the mangled names (v$id, w$id become id, setId). An errored fallback that names no error is written as the fallback element, and a branch that declares its own names is a () => { … } child, so no __err or __item placeholder is left. This view is a reading aid, not the code that runs. A table under it says what each Solid primitive stands for in .rx. Clicking a declaration or a block in the view (<Errored>, <Loading>, <Show>, <For>, createEffect) selects the .rx line it came from (src/link.ts, by name or by place among the module's blocks of that kind). A problem's span is underlined in the .rx editor. The program is kept in the URL hash, the Solid → .rx side included.

site/.assetsignore leaves playground/ out of the static site upload, so deploying reactivescript.dev is unchanged. public/rxc.wasm is built by pnpm wasm and not checked in.

Solid to .rx (prototype)

The header's Solid → .rx button turns the page around: Solid 2.0 on the left, the same program as .rx on the right, from src/torx.ts. The same button turns it back, and each way round the left side gets what the right side showed: the Solid view going in, and the .rx with its helpers.ts coming back, unless the reading left something out, in which case the editor keeps the program it had. It parses the Solid with the Babel parser that Prettier already bundles, so there is no new dependency, and it lists what it cannot read under "Not converted" with the line, rather than guessing. The compiler then checks the .rx, so a Solid program with an await and no Errored boundary gets UNHANDLED_FAILURE.

It reads signals, memos, stores and their draft setters, keyed, draft and value-returning projections, optimistic values and stores with their guesses, actions, createEffect, Show, For, Errored, Loading, error classes, typed catches and boundaries, contexts and their providers, first paints and catches on awaits, loop bodies with their own equations, and prop patterns. A name imported from another .rx module is read as what that module's view declares it (a signal or memo is read as itself, a store as a store), so the converter is given the program's other views, and the .d.rx files say which imports are pure. Plain TypeScript beside a component (data, async functions, anything with statements) moves to helpers.ts, which the .rx imports; JavaScript globals are imported from there too, because .rx has no ambient names.

Three things it found that are not the converter's to fix:

  • A functional write along a path of a plain store, cart.items := items => […], compiles and matches 02 W-6, but the runtime's path writer assigns the function itself (ref/compile/rt-web.ts, the path of source and of the derived store). Converted programs that use splice, or += on a path, do not run correctly until that is fixed.
  • store.users.push(x) in a handler compiles with no diagnostic and is lowered to a push on a read of the store, which Solid ignores.
  • A structured equation, triple = { users: … }, is lowered to createMemo, where 06 ST-1 says createProjection.

Typed errors and context

An error declaration, error NotFound(id: number) => …, reads as class NotFound extends Error with its parameters as fields, and throw NotFound(id) as throw new NotFound(id). A typed catch (e: A | B) starts with if (!(e instanceof A || e instanceof B)) throw e;, and a typed boundary, errored fallback(e: A), is an <Errored> whose fallback rethrows other classes, which Solid hands to the boundary above (R-f-4, R-f-6). A throw in an expression becomes an if (…) throw …; before the return. context, use and provide read as createContext, useContext, and the context as provider around the component's view (07); a provide at a module's top level wraps the app in a Root component. The converter reads all of these back.

The ref/viewdiff harness ran three programs of these forms as the view and as the crate's compiled module on the same seeded clicks: 24 runs, no frame differed.

First paint and catches on awaits

await e -> v (R-7) reads as Solid's loadingValue option, and a question only the browser answers (SV-7b) adds ssrSource: "client". A catch on an awaited answer, await e catch (e: C) => alt, is the promise's own .catch, which rethrows the classes it does not take; on a read it is a memo whose try lets NotReadyError through, so a pending read stays pending. The converter reads these back, and folds the compiler's i$x helper memo into the one equation. viewdiff ran two programs of these forms on seeded answers and rejections: 12 runs, no frame differed.

deferred x = e reads as createDeferred in the view, and the converter reads it back.

Server functions and log

A server fn (12 SF-1) reads as Solid's "use server" function. The compiler hands its body to __rt.serverCall as a generator, so the view puts the body back as an async function with each yield written as await, and drops the __rt.serverRef and sf$ names. Imports the body reads keep their own names. The converter reads it back: a function with the "use server" directive becomes server fn, including one passed to a wrapper such as GET(async function (id) { "use server"; … }). A call from reactive scope becomes an await, and the imports its body reads become import pure, because otherwise asking for the value would be io (SF-1b, SF-2b). An await inside an expression in imperative scope is first bound to a let, since a run suspends only at a statement (AC-1).

log is the one .rx builtin that JavaScript has a name for, so the view writes it as console.log, and the converter reads console.log(…) as log(…) instead of importing console from helpers.ts. A "server fn" example loads a user through one server fn and renames them through an action that calls another.

Completion in the .rx editor now offers the builtins (log, str, len, map and the rest) and the server keyword.

Types on hover, and completion

Both editors answer "what is this" and "what can go here" from TypeScript's language service, in a Web Worker (src/types.worker.ts) that loads on the first hover or completion. The worker is 7.9 MB, 1.7 MB gzipped: TypeScript, its DOM and ES libraries, and Solid's types. Page load does not change.

For .rx it reads what the editor extension reads, the crate's TSX projection of each module with its mappings (analyze, spec/13 TY-1c), so id reads source id: number, an attribute shows its documentation, and user. offers the store's fields. Names every JavaScript module has are left out, because .rx has none. In the Solid → .rx pane it reads the Solid source directly, offers every solid-js export, and adds the import when one is picked.

Verification

  • cargo check --manifest-path compiler/Cargo.toml --all-targets
  • cargo test --release --manifest-path compiler/Cargo.toml, including the new an_unclosed_block_at_the_end_of_input_stops.
  • Every prefix and every one-character deletion of the first six examples, replayed through analyze and app: the slowest step takes 14 ms.
  • In site/playground: pnpm wasm, npx tsc -p ., pnpm build, and pnpm test with pnpm dev running: 24 Playwright checks (three of them for hover and completion in both editors, one each for log, a server fn, the placeholder names, typed errors and context, a first paint and catches, the link between the panes, the mode in the URL, and a two-module program turned around and back), covering the featured await lowering, the primitives table, stores, a rest prop as omit, keyed and draft projections, live updates, WRITE_TO_NON_SOURCE with its rule, guide link and underline, every example, the URL hash, a two-module program, and no page errors.
  • pnpm test:torx (35 cases) and pnpm test:roundtrip (30 cases, and 5 skipped on purpose): each example's .rx goes to the Solid view, back to .rx, and to the view again, which must match; hand-written Solid must convert and compile, or be refused with the expected number of reasons.
  • node tests/roundtrip.corpus.mts over every app in ref, eval and examples of the main repository: 3,249 apps round-trip with no findings: none refused, none rejected by the checker, no view differences. All 3,322 apps show no compiler names in the Solid view.
  • One round of self-review and a Codex review, before the Solid → .rx mode was added; the findings were fixed (operator precedence in the == rewrite, renames inside string literals, store reads scoped to their declaring block, two-module formatting, the URL after adding a file, and others).

Open

  • Hosting: serving it at reactivescript.dev/playground needs a build step that has the wasm32-unknown-unknown target (the editor.yml workflow already builds it) and Vite's base: "/playground/".
  • The rewrite is text-based, so unusual programs can fall back to the compiler's raw JSX, with a note saying so.
  • CI does not run the playground: no workflow runs tsc, the converter suites or the Playwright checks, so the checks on this PR cover the crate only.
  • Hover and completion, server functions, typed errors and context, and the link between the panes have not had a review round either. Completion lists a name and its kind only, auto-import covers solid-js alone, and a .d.rx function with no written return type reads any.
  • The link between the panes covers declarations and blocks. Plain markup lines need source positions from emit::view_jsx.
  • The converter accepts three forms that [Demo, not for merge] Solid TSX frontend checked by ReactiveScript #21's TSX frontend refuses because they change meaning: an object-valued createSignal (a store in .rx), an async handler (an action, whose writes are held), and createEffect (EF-2 compares each input). They should be refused or flagged.
  • The Solid → .rx mode is a prototype and has not had the review rounds the rest had. It does not read refs, Switch/Match, createRenderEffect or custom hooks.
  • Prop defaults stay as createMemo(() => props.x === undefined ? d : props.x) rather than merge: merge keeps an explicit undefined, while 07 §5 applies defaults on undefined.

🤖 Generated with Claude Code

app::app_with takes a reader in place of the disk, so serve.rs can build a
program from the editor's files. With jsx: true each module also carries the
JSX handed to Solid's compiler (emit::view_jsx).
@socket-security

socket-security Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​playwright-core@​1.65.099100809980
Addednpm/​@​solidjs/​web@​2.0.31001008497100
Addednpm/​highlight.js@​11.12.09910010085100
Addednpm/​solid-js@​2.0.3991009796100
Addednpm/​prettier@​3.10.1991009797100
Addednpm/​@​solidjs/​signals@​2.0.310010010098100

View full report

The recovering parse reads a missing statement as an empty one without advancing, so parse_block looped until it found a closing brace. A half-typed handler like `onClick={() => { c` made analyze take 8 to 27 seconds.
… http

The page shows its header and editor while rxc.wasm downloads, the wasm is stripped (5.5 to 4.8 MB), compiled while streaming and retried on a cut-off download, and Share falls back to the copy command where the Clipboard API is missing.
The playground shows only diagnostics from analyze, so it now passes project: false; analyze per keystroke goes from 0.16 to 0.09 ms once warm.
The Solid view wrote the runtime's notation for three things. An effect is now createEffect(inputs, ($0, $1) => …), a store path write or guess is the store setter with a draft function, and the optimistic setter is setOptimisticX. A function whose body holds another un-collapsed return is collapsed on a later pass, which fixes a for inside the first branch of an if.
src/torx.ts parses Solid 2.0 with the Babel parser Prettier bundles and prints .rx, listing what it cannot read by line. Plain TypeScript beside a component moves to helpers.ts. The compiler then checks the result. tests/torx.check.mts and tests/roundtrip.check.mts cover it.
TypeScript's language service runs in a worker that loads on first use. For .rx it reads the crate's TSX projection through its mappings, as the editor extension does; in the Solid pane it reads the source directly, offers every solid-js export and adds the import on a pick. The playground also moves from Solid 2.0.0-rc.21 to 2.0.3, with @solidjs/vite-plugin 3.0.1.
The Solid view pane links to playground.solidjs.com with the view as main.tsx, mounted with render(), its imported modules as tabs and the compiler's scoped CSS injected. The await and action examples gain users.js and names.js, so what their .d.rx files declare can run. A program that would not run there has no link and says why. deferred x = e now reads as createDeferred in the view, and the converter reads it back.
The Solid view writes an error declaration as a class extending Error, a typed
catch or boundary as an instanceof rethrow, and context as createContext,
useContext and the context as provider; the converter reads them back. Problems
are underlined in the .rx editor, and clicking a declaration or block in the
view selects the .rx line it came from.

The header button now swaps the panes, carrying the converted .rx into the
editor, and the mode is kept in the URL. The Solid Playground link, Edit as
.rx and the inline Explain notes are removed.
…dules

The Solid view writes a first paint as loadingValue, a client question as
ssrSource "client", a catch on an await as the promise's catch, and a caught
read as a memo whose try lets NotReadyError through. The converter reads these
back, and reads a name another .rx module exports by what that module's view
declares it as, so a source imported across modules is no longer written as a
call. It also keeps a prelude builtin imported under another name, a keyed
optimistic store's key, and a loop body's own equations.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant