Skip to content

perf(ui): memo reactive scope by editor version + eval guard (SBX-0) - #263

Merged
eliotlim merged 2 commits into
mainfrom
feat/sbx0-eval-guard-memo
Aug 10, 2026
Merged

perf(ui): memo reactive scope by editor version + eval guard (SBX-0)#263
eliotlim merged 2 commits into
mainfrom
feat/sbx0-eval-guard-memo

Conversation

@eliotlim

Copy link
Copy Markdown
Owner

Problem

Every reactive block calls computeScope in its own unmemoized render body, so a doc with B reactive blocks and F formulas does O(B×F) new Function compiles per keystroke. Nothing prevents a new evaluator from landing. Precondition for the OB-146 sandbox (a per-eval QuickJS VM is only viable once this collapses). Board: SBX-0.

Solution

(a) Memoize computeScope keyed on the editor version counter, shared across all reactive call sites — one scope computation per (doc version, render pass). (b) Add no-new-func/no-eval to eslint with explicit per-line disables at the known evaluator sites, so a 6th cannot land silently. New deps: none. No behavior change.

Before / After

Behavior Before After
Scope compute (3 blocks × 3 formulas) 9 compiles on initial render 3 (1 computeScope call/version)
New new Function/eval Lints clean Lint error unless explicitly disabled
Reactive correctness (chained formulas, slider→chart, grouped inputs) Unchanged (verified: 3→6→7, KPI 2→7)

No visual change.

Test procedure

  1. pnpm --filter @book.dev/ui test (kit/reactive: 16 files, 152 tests) — incl. a call-count spy asserting computeScope runs once/version.
  2. Add a new Function('') anywhere → pnpm --filter @book.dev/ui lint errors.

Operational notes

  • SBX-1 (async eval contract) stacks on this branch — merge SBX-0 first.
  • The exported-HTML evaluator (toHtml.ts:1352) is template-string content ESLint can't inspect — covered by SBX-3, not this guard.

Verify: ui lint + typecheck + tests + build green. Gate: code (Quinn).

🤖 Generated with Claude Code

https://claude.ai/code/session_018RUicirLRuuZvjJN13N6yN

@vercel

vercel Bot commented Aug 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
app.book.pub Ready Ready Preview Aug 10, 2026 1:04pm

Request Review

@eliotlim
eliotlim merged commit 883faf4 into main Aug 10, 2026
12 checks passed
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