Skip to content

feat(canvas): scaffold-by-default freeform builds + Tailwind v4 JIT#2949

Open
adamleithp wants to merge 2 commits into
mainfrom
canvas-scaffold-tailwind-v4
Open

feat(canvas): scaffold-by-default freeform builds + Tailwind v4 JIT#2949
adamleithp wants to merge 2 commits into
mainfrom
canvas-scaffold-tailwind-v4

Conversation

@adamleithp

@adamleithp adamleithp commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

What

Two changes to freeform (React) canvas generation, aimed at faster, more consistent first renders.

image image

1. Scaffold-by-default first builds

Freeform canvas generation now seeds the agent with a known-good starter scaffold by default instead of authoring the whole single-file app from scratch. The agent edits a compiling baseline → fewer first-render errors, less boilerplate to (re)derive.

  • New packages/core/src/canvas/freeformStarter.ts — a complete, whitelist-legal .tsx that already wires the easy-to-get-wrong bits: date picker (Popover + quickRanges), theme tokens, per-card loading skeletons, correct typed-node result reading, and a working Refresh.
  • Threaded as a useStarter flag through useGenerateFreeformCanvasbuildFreeformGenerationPrompt.
  • Generate bar shows a checkbox, checked by default; uncheck to build from a blank canvas.

2. Tailwind v4 browser JIT in the edit sandbox

Swapped the edit-mode sandbox Tailwind engine from the v3 Play CDN to the v4 browser build (@tailwindcss/browser@4.3.1, pinned). Quill is authored for v4, so v4's layered preflight, native not-* variants, and @theme inline token mapping let us delete several hand-patches:

  • preflight-off hack → v4 preflight is @layer base, sorts below Quill's @layer components, can't clobber it
  • not-disabled variant shim → native in v4
  • hand-rolled @layer base reset → v4 preflight covers it
  • hand-mirrored color map → @theme inline referencing Quill's CSS vars

v3 kept behind a TAILWIND_ENGINE flag as a one-line fallback. CSP opened for cdn.jsdelivr.net (edit mode only).

3. Authoring-contract tightening

  • Tailwind utilities over inline style.
  • Token-only color with the status-token foreground convention (text-success-foreground, not bare text-success which is the pale fill) — fixes invisible deltas.
  • Date picker rendered bare with <PopoverContent className="w-auto p-0">, no compact (it self-sizes).

Testing

  • pnpm --filter @posthog/core typecheck && test (1727 pass), pnpm --filter @posthog/ui typecheck, biome lint — all green.
  • Validated the v4 swap live over CDP: confirmed the v4 engine loads, @theme inline compiles, Quill components render styled, and the success delta renders readable green.

🤖 Generated with Claude Code

Seed freeform canvas generation with a known-good starter scaffold by
default (opt out in the generate bar): the agent edits a compiling app
instead of authoring boilerplate from scratch — faster, fewer first-render
errors. Threaded as a useStarter flag through the generate hook + prompt
builder; the scaffold wires the easy-to-get-wrong bits (date picker,
theme tokens, loading skeletons, typed-node result reading, refresh).

Swap the edit-mode sandbox Tailwind engine from the v3 Play CDN to the v4
browser JIT (Quill is authored for v4). v4's layered preflight, native
not-* variants, and @theme inline token mapping let us drop the
preflight-off hack, the not-disabled shim, the hand-rolled reset, and the
hand-mirrored color map. Pinned to 4.3.1; v3 kept behind a flag.

Tighten the authoring contract: Tailwind utilities over inline style;
token-only color with the status-token foreground convention
(text-success-foreground, not bare text-success); date picker rendered
bare with PopoverContent w-auto p-0 and no compact.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@adamleithp adamleithp added the Stamphog This will request an autostamp by stamphog on small changes label Jun 26, 2026
@adamleithp adamleithp enabled auto-merge (squash) June 26, 2026 11:34
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown

React Doctor found 1 issue in 1 file · 1 warning.

1 warning

src/features/canvas/freeform/FreeformGenerateBar.tsx

Reviewed by React Doctor for commit 8919327.

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

T1d-complex (439 lines, 8 files) with zero reviews touching sandbox CSP policy. The script-src and connect-src directives now trust the entire cdn.jsdelivr.net origin rather than just the pinned path, in a sandbox that already runs unsafe-eval. The changes are well-reasoned and documented, but a security-adjacent CSP expansion in the code-execution sandbox should have at least one human sign-off before merging.

@stamphog stamphog Bot removed the Stamphog This will request an autostamp by stamphog on small changes label Jun 26, 2026
@greptile-apps

greptile-apps Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "feat(canvas): scaffold-by-default freefo..." | Re-trigger Greptile

Comment thread packages/core/src/canvas/freeformStarter.ts Outdated
Comment thread packages/ui/src/features/canvas/freeform/sandboxRuntime.ts Outdated
…e starter doc

Address PR review:
- CSP now trusts only the ACTIVE engine's CDN (not both v3 + v4), and the v4
  build is path-scoped to cdn.jsdelivr.net/npm/@tailwindcss/ rather than the
  whole jsdelivr origin — narrows the sandbox's egress to what it fetches.
  Re-validated live: v4 still compiles, canvas renders styled, no CSP errors.
- Correct the freeformStarter.ts header (drop stale "COMPACT" / "opt-in";
  scaffold is on by default and the picker self-sizes without compact).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@adamleithp

Copy link
Copy Markdown
Contributor Author

Addressed review feedback in 891932702:

  • stamphog + greptile (CSP scope) — edit-mode CSP now trusts only the active engine's CDN (not both v3 + v4), and the v4 build is path-scoped to cdn.jsdelivr.net/npm/@tailwindcss/ instead of the whole jsdelivr origin. Re-validated live over CDP: v4 still compiles, canvas renders fully styled, no CSP violations.
  • greptile (stale starter doc) — fixed the freeformStarter.ts header (dropped "COMPACT" and "opt-in"; the scaffold is on by default and the picker self-sizes without compact).
  • React Doctor (forwardRef, FreeformGenerateBar.tsx:4) — not changing in this PR. The forwardRef usage is pre-existing; the rule fired only because this PR added useState to that import line. forwardRef still works in React 19 (deprecated, not removed); migrating to ref-as-prop changes the component's public API and is out of scope here.

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