Skip to content

feat(editor): add God Mode code panels and fix large-site crashes - #486

Open
flyingwebie wants to merge 1 commit into
CoreBunch:mainfrom
flyingwebie:feat/god-mode-code-panels
Open

feat(editor): add God Mode code panels and fix large-site crashes#486
flyingwebie wants to merge 1 commit into
CoreBunch:mainfrom
flyingwebie:feat/god-mode-code-panels

Conversation

@flyingwebie

Copy link
Copy Markdown

What

Adds God Mode, a per-user editor mode for structure editors that replaces the properties sidebar with a Code Dock of three panels, and fixes three bugs found while building it.

The Code Dock

  • HTML panel — an editable projection of the selection or the whole page. Edits apply live through a uid-preserving import (importProjectionHtml), so node identity, metadata, and collab state survive an edit; nodes without a uid are new, nodes whose uid disappears are deleted. Destructive or stale applies ask for confirmation. The cursor syncs selection back, with breadcrumbs.
  • CSS panel — an editor over the style-rule registry.
  • JS panel — edits the page script, an ordinary page-scoped code asset visible in the Explorer Code tab.

Each panel formats with Prettier, offers context-aware completions (classes, tokens, data fields), and expands into a full-size editor. Enable under Settings → Preferences; toggle with ⌘⇧G.

The page tree and style-rule registry stay the single source of truth — the panels are projections, never separate storage.

Fixes

  • Site editor crashed the tab ("Aw, Snap") on large sites. Two independent causes: every live HTML apply rewrote the whole projected subtree into the collaboration document and the undo history retained each rewrite until the tab ran out of memory; and connecting to the collaboration server re-assembled the whole site once per page doc instead of once, so a 20-page site did seconds of blocked work and hundreds of MB of allocation at load. An apply now writes only what changed, and the site is assembled once on connect.
  • The toolbar's "N code errors" status is now a button that opens the first error's file in the Code Editor, whose Problems list shows every error with its file:line:column. Before, the count was a passive label and the Problems list only appeared once a script file was already open.
  • Publish validation failed with Could not resolve "<package>" for a dependency the site declares. The runtime dependency cache lives in the OS temp dir; temp cleaners delete package files by age while leaving the install-complete marker behind, so the server kept trusting an emptied cache. A cache now counts as installed only while every locked package is on disk, and a reaped one is reinstalled on demand. New optional RUNTIME_CACHE_DIR moves the cache to a persistent path (documented in .env.example; must not sit under UPLOADS_DIR, which is served publicly).

Why

Structure editors want direct code control over a page without leaving the visual editor or giving up the page tree as the source of truth. Building the HTML projection surfaced the collab/undo memory blowup, which affected large sites regardless of God Mode.

Impact

  • Users: new opt-in editor mode, off by default. Large sites load meaningfully faster and no longer crash the tab.
  • Deployments: optional RUNTIME_CACHE_DIR. No schema changes, no migrations.
  • Developers: two new engine modules, @core/cssProjection and the projection import/render paths (RenderConfig.projection, importProjectionHtml). Both are barrel-exported and covered by the deep-import gate.

Docs

  • New: docs/features/god-mode.md
  • Updated: docs/editor.md, docs/features/publisher.md, docs/features/html-import.md, docs/features/site-shell.md, docs/features/editor-preferences.md, docs/server.md, docs/README.md
  • CHANGELOG.md entry filed under ## Unreleased — happy to fold it into whichever version you cut.

Verification

bun install
bun run build   # tsc -b && vite build — clean
bun test        # 7040 pass, 0 fail, 770 files
bun run lint    # clean

New tests cover the code-editor panels, uid-preserving projection import, CSS projection, stylesheet edit planning, the connect-scope change, and the dependency-cache reap path. The codemirror-lazy-only and bundle-size-budgets architecture gates were updated for the new lazy chunks.

Notes

Branched from current main. Two dependencies added: prettier (panel formatting) and babel-plugin-react-compiler (previously relied on transitively — now declared explicitly).

God Mode is a per-user editor mode for structure editors: it replaces the
properties sidebar with a Code Dock of three panels.

- HTML panel — an editable projection of the selection or the whole page.
  Edits apply live through a uid-preserving import, so node identity,
  metadata, and collab state survive an edit. Destructive or stale applies
  ask for confirmation. The cursor syncs selection back, with breadcrumbs.
- CSS panel — an editor over the style-rule registry.
- JS panel — edits the page script, an ordinary page-scoped code asset.

Each panel formats with Prettier, offers context-aware completions (classes,
tokens, data fields), and expands into a full-size editor. Enable it under
Settings -> Preferences; toggle with Cmd+Shift+G.

Alongside it, three fixes:

- Fixed the site editor crashing the tab ("Aw, Snap") on large sites. Every
  live HTML apply rewrote the whole projected subtree into the collaboration
  document and the undo history retained each rewrite; separately, connecting
  to the collaboration server re-assembled the whole site once per page doc
  instead of once, so a 20-page site did seconds of blocked work and hundreds
  of megabytes of allocation at load. An apply now writes only what changed,
  and the site is assembled once on connect.
- Made the toolbar's "N code errors" status a button that opens the first
  error's file in the Code Editor. It was a passive label, and the Problems
  list only appeared once a script file was already open.
- Fixed publish validation failing with `Could not resolve "<package>"` for a
  declared dependency. The runtime dependency cache lives in the OS temp dir
  and temp cleaners delete package files by age while leaving the
  install-complete marker behind, so the server kept trusting an emptied
  cache. A cache now counts as installed only while every locked package is
  on disk, and a reaped one is reinstalled on demand. `RUNTIME_CACHE_DIR`
  moves the cache to a persistent path.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@socket-security

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
Addedprettier@​3.9.6981009794100

View full report

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