[PR #4453] [MERGED] Fix theme editor live preview lag #6385

Closed
opened 2026-10-23 04:09:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4453
Author: @SpicyMarinara
Created: 8/2/2026
Status: ✅ Merged
Merged: 8/2/2026
Merged by: @SpicyMarinara

Base: staging ← Head: agent/fix-theme-editor-preview-lag


📝 Commits (1)

  • 5374008 Fix theme editor live preview lag

📊 Changes

2 files changed (+83 additions, -14 deletions)

View changed files

📝 e2e/core-flows.e2e.ts (+54 -0)
📝 packages/client/src/components/panels/SettingsPanel.tsx (+29 -14)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #4452

Why this change

The custom theme editor rewrote its app-level preview stylesheet for every character typed. In the supplied Opera performance recording, each rewrite invalidated styles across 2,754 elements and took roughly 55–71 ms, making dense-theme editing visibly fall behind input. JavaScript and garbage collection were comparatively small, so the root cause was repeated full-document style recalculation rather than a sustained heap leak.

What changed

  • Debounce live-preview stylesheet replacement until CSS input has settled for 300 ms.
  • Preserve the last rendered preview while typing, then keep the settled preview after the saved active-theme stylesheet.
  • Remove preview CSS immediately when Preview is disabled or the editor unmounts.
  • Add desktop and mobile browser regression coverage proving a typing burst causes one settled stylesheet mutation instead of one mutation per keystroke.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Automated validation completed:

  • pnpm check
  • pnpm exec playwright test e2e/core-flows.e2e.ts --grep 'custom theme live preview batches stylesheet updates while typing' (2 passed: desktop Chromium and mobile Chromium)
  • git diff --check

Manual verification notes

  • Manually verify rapid editing of a dense custom theme remains responsive in Opera.
  • Manually verify the preview updates after typing pauses.
  • Manually disable and re-enable Preview, then close the editor, and verify preview CSS does not remain active.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

The supplied Opera DevTools trace is the performance evidence for the original issue. The regression test observes the live-preview stylesheet directly on desktop and mobile.

Summary by CodeRabbit

  • Bug Fixes

    • Improved custom theme live preview performance by batching updates during rapid CSS editing.
    • Ensured preview styles are consistently removed when preview mode ends or the editor closes.
    • Preserved correct style ordering so live previews remain visible alongside saved theme styles.
  • Tests

    • Added end-to-end coverage for batched theme preview updates and cleanup behavior.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/4453 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 8/2/2026 **Status:** ✅ Merged **Merged:** 8/2/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `agent/fix-theme-editor-preview-lag` --- ### 📝 Commits (1) - [`5374008`](https://github.com/Pasta-Devs/Marinara-Engine/commit/53740089a68d4d1778cc40b281234f33dc459e25) Fix theme editor live preview lag ### 📊 Changes **2 files changed** (+83 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `e2e/core-flows.e2e.ts` (+54 -0) 📝 `packages/client/src/components/panels/SettingsPanel.tsx` (+29 -14) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #4452 ## Why this change The custom theme editor rewrote its app-level preview stylesheet for every character typed. In the supplied Opera performance recording, each rewrite invalidated styles across 2,754 elements and took roughly 55–71 ms, making dense-theme editing visibly fall behind input. JavaScript and garbage collection were comparatively small, so the root cause was repeated full-document style recalculation rather than a sustained heap leak. ## What changed - Debounce live-preview stylesheet replacement until CSS input has settled for 300 ms. - Preserve the last rendered preview while typing, then keep the settled preview after the saved active-theme stylesheet. - Remove preview CSS immediately when Preview is disabled or the editor unmounts. - Add desktop and mobile browser regression coverage proving a typing burst causes one settled stylesheet mutation instead of one mutation per keystroke. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Automated validation completed: - `pnpm check` - `pnpm exec playwright test e2e/core-flows.e2e.ts --grep 'custom theme live preview batches stylesheet updates while typing'` (2 passed: desktop Chromium and mobile Chromium) - `git diff --check` ### Manual verification notes - Manually verify rapid editing of a dense custom theme remains responsive in Opera. - Manually verify the preview updates after typing pauses. - Manually disable and re-enable Preview, then close the editor, and verify preview CSS does not remain active. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) The supplied Opera DevTools trace is the performance evidence for the original issue. The regression test observes the live-preview stylesheet directly on desktop and mobile. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved custom theme live preview performance by batching updates during rapid CSS editing. * Ensured preview styles are consistently removed when preview mode ends or the editor closes. * Preserved correct style ordering so live previews remain visible alongside saved theme styles. * **Tests** * Added end-to-end coverage for batched theme preview updates and cleanup behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:09:55 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#6385
No description provided.