Skip to content

perf(ui): defer custom theme import to settings - #130710

Merged
steipete merged 1 commit into
mainfrom
codex/sweep-lazy-theme-import-20260826
Aug 27, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/sweep-lazy-theme-import-20260826

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Control UI startup eagerly loaded the custom-theme URL parser, network importer, and external token conversion, even though only the lazy Appearance settings page uses them. Startup sat at the committed performance ceiling, making unrelated PR builds fail as embedded build metadata and chunk hashes changed.

This moves import-only work into the existing lazy ConfigPage boundary. Saved palette validation and CSS restoration remain on startup, so an already selected custom theme still appears immediately.

Why This Change Was Made

The existing app/custom-theme.ts owned two different lifetimes: restoring browser-local theme state at boot and importing an external theme on demand. ConfigPage now directly imports its own custom-theme-import.ts; the eager owner exposes only the shared validation primitives it needs. The old importer path is removed, with no forwarding wrapper, new dynamic import, dependency, configuration option, or compatibility branch.

Independent AST review confirms the existing function bodies and constants were preserved. The 200,000-byte response cap, 10-second timeout, redirect policy, CSS/font validation, token order, cancellation, and stale-owner handling are unchanged. Production is +324/-314, net +10 lines, solely for the module/import boundary; tests are +46/-8, net +38. No performance budget, generated boot manifest, translation baseline, or changelog change.

User Impact

The initial Control UI download no longer includes theme import work that is only needed in Settings. Import, retry, clearing a pending import, newer server selections, and saved-theme restoration retain their behavior.

With identical build identity, Node 26.7.0 and the pinned UI dependency closure, including Pako 3.0.1:

Measurement Base Candidate
Startup JS raw bytes 1,137,152 1,130,676
Startup JS gzip bytes 343,443 341,304
Startup JS requests 8 8

The existing 343,442-byte ceiling is unchanged. Startup falls by 6,476 raw bytes and 2,139 gzip bytes. A second build with current branch metadata measured 341,318 gzip bytes. This is a startup optimization: total gzip across all JavaScript chunks increases by 1,128 bytes because compression boundaries change; total JavaScript requests remain 338.

Evidence

  • Built artifacts place all inspected import-only markers solely in the lazy ConfigPage chunk. Saved-theme validation and the style owner remain in initial JavaScript. All 770 compressed sidecars decode to their source bytes.
  • 40 focused theme/settings tests and 57 ConfigPage/bootstrap ownership tests passed. Three targeted Chromium scenarios passed against freshly built candidate bundles, including failed import followed by successful retry and reload, Clear during an in-flight replacement, and a newer server selection.
  • The import/reload scenario also passed against freshly built immutable base. It checks expected imported CSS, the exact profileless theme-only server write, browser-local palette persistence, restoration after reload, and no second external fetch. The first version exposed an incomplete mock server response and failed identically on base; only that fixture was corrected.
  • A separate unauthenticated request through the unchanged production importer successfully imported the public Amethyst Haze theme, yielding 52 light and 52 dark tokens within the existing timeout and response cap. This is separate from the browser scenarios, whose Gateway and theme responses are mocked.
  • Final structured Codex review completed with no P0 findings. The full local changed-file gate passed all 19 checks, including unused exports, core test and UI type checks, i18n verification, lint, formatting, and repository boundary guards.

The screenshots below come from separate baseline and candidate browser runs. They are byte-identical after reloading the saved fixture palette, demonstrating preserved appearance rather than a visual redesign. No personal data, operator state, or credentials are included.

Before:

Baseline: restored Light Green theme after reload

After:

Candidate: restored Light Green theme after reload

@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui size: L maintainer Maintainer-authored PR labels Aug 27, 2026
@steipete
steipete marked this pull request as ready for review August 27, 2026 05:17
@steipete

Copy link
Copy Markdown
Contributor Author

Final verification for fe66623 is complete. Exact-head CI passed, including build-artifacts. Hosted startup JavaScript measured 341,297 bytes gzip in 8 requests, leaving 2,145 bytes below the unchanged 343,442-byte ceiling.

Root and two independent scoped reviews found no actionable source issue. The existing lazy ConfigPage owns external import work; saved palette validation and immediate CSS restoration remain eager. The preserved runtime bodies, emitted chunk placement, and controlled local measurements establish actual code movement, not a metadata/hash reroll. Production is +324/-314 (net +10 for the static module boundary), tests +46/-8. Total all-chunk gzip increases 1,128 bytes from compression placement, as disclosed in the PR.

Local verification passed 97 owner/settings/bootstrap tests, three candidate Chromium scenarios, the same import/retry/reload scenario on immutable base, all 19 changed-file checks, and one separate real unauthenticated public theme import. Browser Gateway/theme responses are mocked; the independent public importer request is real. Baseline/candidate saved-theme screenshots are attached in the body and are byte-identical. Structured Codex autoreview reported no P0 findings; its threshold is not an all-priority review claim.

The focused test commands used the saved, single-worker UI configurations through node scripts/run-vitest.mjs run --config <proof-config> --maxWorkers 1; the browser configuration additionally used --configLoader runner and selected custom-theme import|delayed custom-theme replacement|newer server-applied theme. The full local gate command was:

env -u OPENCLAW_TESTBOX OPENCLAW_VITEST_MAX_WORKERS=1 RAYON_NUM_THREADS=2 node scripts/check-changed.mjs --timed --base HEAD --head HEAD -- ui/src/app/custom-theme.test.ts ui/src/app/custom-theme.ts ui/src/e2e/appearance-settings-defaults.e2e.test.ts ui/src/pages/config/config-page.custom-theme.test.ts ui/src/pages/config/config-page.ts ui/src/pages/config/custom-theme-import.ts

The latest ClawSweeper comment remains a review-started placeholder; it contains no findings or Rank-up moves to address. No published finding is being skipped. The separately reproduced lazy Retry/storage/lifecycle defects remain a separate repair and do not broaden this sealed change. Proceeding through native prepare/merge.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 27, 2026, 1:26 AM ET / 05:26 UTC.

ClawSweeper review

What this changes

The PR moves custom-theme URL importing into the lazy Appearance Settings bundle while leaving saved-theme validation and style restoration in the startup bundle.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this maintainer PR open: the lazy import split is sound, but the branch also removes the existing reduced-motion guard from two Settings scroll paths, reintroducing a current-main accessibility regression.

Priority: P1
Reviewed head: fe66623794dd2bb045fc657bcc97af3d2697053d

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The lazy-boundary refactor is coherent, but a concrete P1 accessibility regression blocks merge.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable: this is a maintainer-authored PR; its linked browser evidence supports theme restoration but does not demonstrate the reduced-motion paths introduced by the branch.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable: this is a maintainer-authored PR; its linked browser evidence supports theme restoration but does not demonstrate the reduced-motion paths introduced by the branch.
Evidence reviewed 7 items Lazy ownership boundary: The Settings route dynamically loads the Config page; the Config page statically imports the moved URL importer, while startup retains only saved-theme restoration.
Startup behavior retained: Bootstrap still applies the parsed saved theme through the style-tag owner before the settings route is visited.
Current reduced-motion contract: Current main resolves requested smooth scrolling to auto when the operating system requests reduced motion, and both affected Settings paths use that helper.
Findings 1 actionable finding [P1] Preserve reduced-motion behavior in Settings scrolling
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs ui/src/lib/scroll-behavior.test.ts

Result: FAIL (failed) — step 1 expect_output uses auto for smooth scrolling under reduced motion: expected terminal output was not visible within 30 seconds: "uses auto for smooth scrolling under reduced motion"

[vitest] explicit test/source file(s) not found:
  - ui/src/lib/scroll-behavior.test.ts
[vitest] FAILED (exit 1)
[test] FAILED (exit 1)

Assertions:

  • FAIL expect_output: uses auto for smooth scrolling under reduced motion

How this fits together

Control UI startup reads saved settings and restores a selected custom theme immediately. The lazy Settings route loads the Appearance page, where a user can import a theme URL and persist the resulting palette.

flowchart LR
  A[Control UI startup] --> B[Saved theme validation]
  B --> C[Theme CSS restoration]
  D[Appearance Settings route] --> E[Lazy Config page]
  E --> F[Theme URL importer]
  F --> G[Validated palette persistence]
  G --> B
Loading

Before merge

  • Preserve reduced-motion behavior in Settings scrolling (P1) - Restore resolveScrollBehavior() here and in view-appearance.ts:135. Current main routes these imperative scrolls through the helper so prefers-reduced-motion: reduce becomes auto; the literal smooth calls reintroduce the regression fixed by commit 4bc659744181ef6ffd241b957b3d88ea72d48a8a.
  • Resolve merge risk (P1) - Until the two calls again use the shared resolver, Settings deep links and opening the custom-theme importer animate despite an existing reduced-motion preference.
  • Complete next step (P2) - This protected maintainer PR needs a normal author/maintainer update; no repair lane is proposed.

Findings

  • [P1] Preserve reduced-motion behavior in Settings scrolling — ui/src/pages/config/config-page.ts:603
Agent review details

Security

None.

PR surface

Source +10, Tests +38. Total +48 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 324 314 +10
Tests 3 46 8 +38
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 370 322 +48

Review metrics

Metric Value Why it matters
Production versus test delta production +326/-318 (net +8); tests +46/-8 (net +38) The small net production growth is primarily the lazy-module split; the accidental removal of two accessibility-policy imports must not ship.

Merge-risk options

Maintainer options:

  1. Restore Settings motion policy (recommended)
    Retain the lazy theme-import split, restore resolveScrollBehavior() at both changed scroll sites, and add focused reduced-motion caller coverage before merge.

Technical review

Best possible solution:

Keep the lazy importer boundary, but restore the shared reduced-motion resolver at both Settings scroll call sites and cover those callers under a reduced-motion media query.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: with matchMedia('(prefers-reduced-motion: reduce)') true, each changed literal smooth call bypasses the current resolver that returns auto.

Is this the best way to solve the issue?

No: the importer move is the right owner boundary, but removing the unrelated Settings motion-policy calls is not required for it and regresses current behavior.

Full review comments:

  • [P1] Preserve reduced-motion behavior in Settings scrolling — ui/src/pages/config/config-page.ts:603
    Restore resolveScrollBehavior() here and in view-appearance.ts:135. Current main routes these imperative scrolls through the helper so prefers-reduced-motion: reduce becomes auto; the literal smooth calls reintroduce the regression fixed by commit 4bc659744181ef6ffd241b957b3d88ea72d48a8a.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 95c318669520.

Labels

Label changes:

  • add P1: The patch would reintroduce a current Settings accessibility regression for people who request reduced motion.
  • add merge-risk: 🚨 compatibility: Existing users’ operating-system reduced-motion preference stops governing two established Settings interactions if this branch merges.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.

Label justifications:

  • P1: The patch would reintroduce a current Settings accessibility regression for people who request reduced motion.
  • merge-risk: 🚨 compatibility: Existing users’ operating-system reduced-motion preference stops governing two established Settings interactions if this branch merges.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.

Evidence

What I checked:

  • Lazy ownership boundary: The Settings route dynamically loads the Config page; the Config page statically imports the moved URL importer, while startup retains only saved-theme restoration. (ui/src/pages/config/route.ts:35, fe66623794dd)
  • Startup behavior retained: Bootstrap still applies the parsed saved theme through the style-tag owner before the settings route is visited. (ui/src/app/bootstrap.ts:97, fe66623794dd)
  • Current reduced-motion contract: Current main resolves requested smooth scrolling to auto when the operating system requests reduced motion, and both affected Settings paths use that helper. (ui/src/lib/scroll-behavior.ts:1, 95c318669520)
  • Regression provenance: Commit 4bc6597 introduced the shared reduced-motion policy for imperative Settings scrolling; current main contains that commit. (ui/src/pages/config/config-page.ts:604, 4bc659744181)
  • PR removes the policy at both call sites: The PR-base comparison removes resolveScrollBehavior imports and substitutes literal smooth behavior in route-target scrolling and custom-theme-input focus. (ui/src/pages/config/config-page.ts:603, fe66623794dd)
  • Existing test coverage and gap: The importer relocation retains focused import and race coverage, while the current reduced-motion helper test establishes the intended behavior; neither changed test exercises these two Settings callers under reduced motion. (ui/src/lib/scroll-behavior.test.ts:9, 95c318669520)

Likely related people:

  • AGI ASI: Authored the current-main reduced-motion repair that this branch removes from the two Settings paths. (role: recent accessibility-fix author; confidence: high; commits: 4bc659744181; files: ui/src/lib/scroll-behavior.ts, ui/src/pages/config/config-page.ts, ui/src/pages/config/view-appearance.ts)
  • Peter Steinberger: Current history includes the custom-theme performance refactor and earlier appearance/import lifecycle work in the affected Config page. (role: recent Control UI and custom-theme contributor; confidence: medium; commits: fe66623794dd, d585c0c1ec49; files: ui/src/app/custom-theme.ts, ui/src/pages/config/config-page.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Restore the shared resolver at both Settings scroll sites.
  • Add focused caller-level coverage showing reduced motion selects auto for route-target scrolling and custom-theme input focus.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 42ce03e into main Aug 27, 2026
161 checks passed
@steipete
steipete deleted the codex/sweep-lazy-theme-import-20260826 branch August 27, 2026 05:50
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

app: web-ui App: web-ui maintainer Maintainer-authored PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant