-
Notifications
You must be signed in to change notification settings - Fork 122
feat(repl): Lynx REPL — interactive playground with GitHub Pages deployment #2292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2b1c7c4
feat(repl): add Lynx REPL package with @lynx-js/types Monaco integration
Huxpro f7bb4fe
fix(repl,web-runtime): stabilize preview layout and safe dispose life…
Huxpro 3f6fd78
fix(repl): correct EditorPane collapse/expand layout behavior
Huxpro 317224c
fix(repl): cancel stale debounce after switching example
Huxpro f77c957
feat(repl): content-aware panel height distribution on example switch
Huxpro f80fab6
feat(repl): new examples, accurate render timing, and mobile UX polish
Huxpro 1ea3eaa
chore(lint): ignore repl/src/examples from ESLint and Biome
Huxpro dc0570d
feat(repl): add reload button and fix console clearing behavior
Huxpro bf29cd4
feat(ci): deploy repl to GitHub Pages alongside docs
Huxpro e426ed4
fix(repl,web-platform): inject callDestroyLifetimeFun for raw PAPI ca…
Huxpro 0e9063f
fix(ci): fix code-style-check and sherif CI failures
Huxpro 19e139e
chore: merge main and resolve pnpm-lock.yaml conflict
Huxpro e69cbff
fix(repl): fix CI failures for build and code-style-check
Huxpro c3870f4
fix(repl): move cn utility out of gitignored lib directory
Huxpro 3780932
fix(repl): fix ESLint errors for CI compliance
Huxpro 7a36d50
chore(repl): remove AI-generated instructions file
Huxpro fa6af35
Merge branch 'main' into Huxpro/repl
Huxpro f432b10
Merge branch 'main' into Huxpro/repl
Huxpro 9d54243
fix(repl): address PR review feedback
Huxpro 078f1b1
chore(repl): remove unused @lynx-js/offscreen-document devDependency
Huxpro d87eb22
fix(repl): address remaining PR review feedback
Huxpro 378392a
fix(repl): use npm: alias for @types/react instead of sherif exclusion
Huxpro 13916db
chore: dedupe pnpm lockfile
Huxpro 398429f
Merge branch 'main' into Huxpro/repl
Huxpro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| src/generated/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # @lynx-js/repl | ||
|
|
||
| A **pure-browser** playground for Vanilla Lynx. Users write raw Element PAPI code and see it rendered in real time — no local toolchain, no server, no install. | ||
|
|
||
| ## Architecture Principle: Pure Browser, Zero Server | ||
|
|
||
| This REPL runs **entirely in the browser**. The built artifact is a static site that can be deployed to any CDN or GitHub Pages. There is no compilation server, no Node.js dependency at runtime, and no network round-trip in the edit-preview loop. | ||
|
|
||
| An alternative approach would be to run a local (or remote) Node.js server that invokes rspack for each edit — effectively a browser-based editor bolted onto the real build pipeline. We deliberately chose **not** to do this because: | ||
|
|
||
| 1. **If you need a local server, you already have Node.js** — at that point `rspeedy dev` gives you a strictly better experience (your own editor, incremental builds, HMR, full plugin pipeline). | ||
| 2. A server-backed REPL sits in an awkward middle ground: it loses the zero-setup advantage of a pure-browser tool while offering a worse DX than the real toolchain. | ||
| 3. The value of this REPL is precisely that it **does not overlap** with `rspeedy dev`. It serves a different audience (learners, docs, quick experiments) with a different tradeoff (instant access, limited features). | ||
|
|
||
| ## Where We Cut Into the Build Pipeline | ||
|
|
||
| A standard Lynx project goes through 8 steps from source to bundle: | ||
|
|
||
| ```text | ||
| Step What happens Tool / Plugin | ||
| ──── ────────────────────────────────── ───────────────────────────── | ||
| 1. Source Transform (JSX/TS → JS) rspack loader (SWC) | ||
| 2. Module Resolution (import/require) rspack resolver | ||
| 3. CSS Processing (CSS → LynxStyleNode) @lynx-js/css-serializer | ||
| 4. Bundling (multi-file → chunks) rspack | ||
| 5. Asset Tagging (lynx:main-thread) MarkMainThreadPlugin | ||
| 6. Template Assembly (assets → data) LynxTemplatePlugin | ||
| 7. Encoding (data → binary/JSON) @lynx-js/tasm / WebEncodePlugin | ||
| 8. Emit (write to disk) rspack compilation | ||
| ``` | ||
|
|
||
| This REPL **enters at step 6** and takes a shortcut: | ||
|
|
||
| ```text | ||
| rspeedy dev (full pipeline): | ||
| [1] → [2] → [3] → [4] → [5] → [6] → [7] → [8] → lynx-view (via URL fetch) | ||
|
|
||
| This REPL (pure browser): | ||
| [3'] → [6'] ─────────→ lynx-view (via callback) | ||
| ``` | ||
|
|
||
| - **Step 3':** Parse user CSS in-browser via `css-tree` (pure JS) and a simplified `genStyleInfo` (adapted from `@lynx-js/css-serializer`) to produce `styleInfo`. | ||
| - **Step 6':** Directly construct a `LynxTemplate` JS object from the user's code strings and the processed `styleInfo`. No webpack compilation, no asset pipeline. | ||
| - **Delivery:** The template object is handed to `<lynx-view>` via the `customTemplateLoader` callback — no encoding, no file I/O, no URL fetch. | ||
|
|
||
| Steps 1, 2, 4, 5 are skipped entirely because the user writes final-form JS (no JSX, no imports, no multi-file). Steps 7–8 are skipped because `<lynx-view>` can consume a `LynxTemplate` object directly. | ||
|
|
||
| ## Functional Boundaries | ||
|
|
||
| What this REPL **can** do: | ||
|
|
||
| - All Element PAPIs (`__CreateElement`, `__AppendElement`, `__AddInlineStyle`, etc.) | ||
| - CSS class selectors, `@keyframes`, `@font-face`, CSS variables | ||
| - Inline styles via `__AddInlineStyle` | ||
| - Real-time preview with Lynx Web runtime (`<lynx-view>`) | ||
| - Dual-thread model: main-thread.js (Lepus) + background.js (Web Worker) | ||
|
|
||
| What this REPL **cannot** do (by design): | ||
|
|
||
| - `import` / `require` — no module resolution, no bundler | ||
| - JSX / TypeScript — no source transform | ||
| - Export `.lynx.bundle` — requires `@lynx-js/tasm` (Node native addon) | ||
| - Export `.web.json` binary — possible in future but not a priority | ||
| - Multi-file projects — single main-thread.js + background.js + index.css | ||
|
|
||
| Users who need any of the above should use `rspeedy dev`. | ||
|
|
||
| ## Target Capability: L0 + L1 | ||
|
|
||
| We target two capability levels, both achievable in pure browser: | ||
|
|
||
| | Level | Capability | Browser dependency | | ||
| | ------------- | ----------------------------------- | --------------------------- | | ||
| | **L0** (done) | Raw Element PAPI with inline styles | None (zero extra KB) | | ||
| | **L1** (done) | + CSS class selectors | `css-tree` (~200KB gzipped) | | ||
|
|
||
| Higher levels (JSX, module imports, bundle export) are **not planned** — they would move toward `rspeedy dev` territory without matching its DX. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en" data-theme="dark"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Lynx REPL</title> | ||
| <!-- Critical CSS: prevent flash of white background before main CSS loads. | ||
| Uses the CSS variable so the background adapts when the theme changes; | ||
| the fallback #1e1e1e is only used during the brief initial load. --> | ||
| <style> | ||
| html, body, #app { | ||
| background: var(--repl-bg, #1e1e1e); | ||
| height: 100%; | ||
| width: 100%; | ||
| margin: 0; | ||
| overflow: hidden; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <div id="app"></div> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| { | ||
| "name": "@lynx-js/repl", | ||
| "version": "0.0.1", | ||
| "private": true, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/lynx-family/lynx-stack.git", | ||
| "directory": "packages/repl" | ||
| }, | ||
| "license": "Apache-2.0", | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "node scripts/collect-lynx-types.mjs && rsbuild build", | ||
| "dev": "node scripts/collect-lynx-types.mjs && rsbuild dev" | ||
| }, | ||
| "dependencies": { | ||
| "@radix-ui/react-select": "^2.2.6", | ||
| "class-variance-authority": "^0.7.1", | ||
| "clsx": "^2.1.1", | ||
| "lucide-react": "^0.575.0", | ||
| "react": "^19.2.4", | ||
| "react-dom": "^19.2.4", | ||
| "react-resizable-panels": "^4.6.5", | ||
| "tailwind-merge": "^3.4.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@lynx-js/lynx-core": "0.1.3", | ||
| "@lynx-js/type-element-api": "0.0.3", | ||
| "@lynx-js/types": "3.7.0", | ||
| "@lynx-js/web-constants": "workspace:*", | ||
| "@lynx-js/web-core": "workspace:*", | ||
| "@lynx-js/web-elements": "workspace:*", | ||
| "@lynx-js/web-mainthread-apis": "workspace:*", | ||
| "@lynx-js/web-platform-rsbuild-plugin": "workspace:*", | ||
| "@lynx-js/web-worker-rpc": "workspace:*", | ||
| "@lynx-js/web-worker-runtime": "workspace:*", | ||
| "@rsbuild/core": "catalog:rsbuild", | ||
| "@rsbuild/plugin-react": "^1.4.5", | ||
| "@tailwindcss/postcss": "^4.2.1", | ||
| "@types/css-tree": "^2.3.11", | ||
| "@types/react": "npm:@types/react@^19.2.14", | ||
| "@types/react-dom": "^19.2.3", | ||
| "css-tree": "^3.1.0", | ||
| "hyphenate-style-name": "^1.1.0", | ||
| "monaco-editor": "^0.52.2", | ||
| "postcss": "^8.5.6", | ||
| "tailwindcss": "^4.2.1", | ||
| "tslib": "^2.8.1", | ||
| "wasm-feature-detect": "^1.8.0" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Copyright 2026 The Lynx Authors. All rights reserved. | ||
| // Licensed under the Apache License Version 2.0 that can be found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
|
|
||
| export default { | ||
| plugins: { | ||
| '@tailwindcss/postcss': {}, | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { defineConfig } from '@rsbuild/core'; | ||
| import { pluginReact } from '@rsbuild/plugin-react'; | ||
| import { pluginWebPlatform } from '@lynx-js/web-platform-rsbuild-plugin'; | ||
| import path from 'node:path'; | ||
|
|
||
| export default defineConfig({ | ||
| source: { | ||
| entry: { | ||
| index: './src/index.tsx', | ||
| }, | ||
| include: [/node_modules[\\/]@lynx-js[\\/]/, /@lynx-js[\\/]/], | ||
| }, | ||
| output: { | ||
| target: 'web', | ||
| assetPrefix: process.env.ASSET_PREFIX, | ||
| distPath: { | ||
| root: 'dist', | ||
| }, | ||
| overrideBrowserslist: ['Chrome > 118'], | ||
| }, | ||
| html: { | ||
| title: 'Lynx REPL', | ||
| template: './index.html', | ||
| }, | ||
| tools: { | ||
| rspack: { | ||
| ignoreWarnings: [ | ||
| (warning) => | ||
| warning.module?.resource?.includes('monaco-editor') | ||
| && warning.message.includes('Critical dependency') | ||
| && warning.message.includes('require function is used in a way'), | ||
| (warning) => | ||
| warning.module?.resource?.includes('monaco-editor') | ||
| && warning.message.includes( | ||
| '"__filename" is used and has been mocked', | ||
| ), | ||
| (warning) => | ||
| warning.module?.resource?.includes('monaco-editor') | ||
| && warning.message.includes( | ||
| '"__dirname" is used and has been mocked', | ||
| ), | ||
| ], | ||
| resolve: { | ||
| alias: { | ||
| '@': path.resolve(__dirname, 'src'), | ||
| '@lynx-js/type-element-api/types/element-api.d.ts': path.resolve( | ||
| __dirname, | ||
| 'node_modules/@lynx-js/type-element-api/types/element-api.d.ts', | ||
| ), | ||
| }, | ||
| fallback: { | ||
| module: false, | ||
| }, | ||
| modules: [ | ||
| 'node_modules', | ||
| path.resolve(__dirname, 'node_modules'), | ||
| path.resolve(__dirname, '../../node_modules'), | ||
| ], | ||
| symlinks: true, | ||
| }, | ||
| }, | ||
| }, | ||
| performance: { | ||
| chunkSplit: { | ||
| strategy: 'all-in-one', | ||
| }, | ||
| }, | ||
| plugins: [ | ||
| pluginReact(), | ||
| pluginWebPlatform({ | ||
| polyfill: false, | ||
| }), | ||
| ], | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.