[PR #7641] [MERGED] perf(chat): read the selection on scroll only while text is selected #7852

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7641
Author: @Gunterlie
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/14/2026
Merged by: @Gunterlie

Base: staging ← Head: perf/selection-toolbar-scroll


📝 Commits (1)

  • e467b67 perf(chat): selection lorebook button reads the selection on scroll only while text is selected

📊 Changes

1 file changed (+16 additions, -6 deletions)

View changed files

📝 packages/client/src/components/chat/SelectionLorebookButton.tsx (+16 -6)

📄 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 #7640

Why this change

  • SelectionLorebookButton listens to every scroll in the app (capture on window) and to resize. Each event reads window.getSelection() in the next frame, and that read forces a layout. A package screen that scrolls over a mounted chat paid this on every frame, even with no text selected. On Slurp's Discover screen it cost 592 ms of forced layout when the screen opened, at 4× CPU throttle.

What changed

  • packages/client/src/components/chat/SelectionLorebookButton.tsx: selectionchange records whether a non-collapsed selection exists and schedules the read as before. Scroll and resize schedule the read only while such a selection exists, so a selection that scrolls keeps its button in place.

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

Manual verification notes

  • Agent run: pnpm install --frozen-lockfile and pnpm check on this branch (based on origin/staging 154a33092) exited 0.
  • The cost was measured on a production install (headless Chromium, 390×844, 4× CPU throttle, CDP profiler). I did not measure this branch in a browser, and I did not click through text selection by hand. A reviewer should select text in a chat message, scroll the chat, and check that the button follows the selection and goes away when the selection collapses.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) 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)

  • No visual change.

Summary by CodeRabbit

  • Bug Fixes
    • Improved selection tracking so scrolling and resizing update the button only when text is selected. Selection-change and viewport event handlers are also cleaned up when no longer needed.

🔄 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/7641 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@Gunterlie](https://github.com/Gunterlie) **Base:** `staging` ← **Head:** `perf/selection-toolbar-scroll` --- ### 📝 Commits (1) - [`e467b67`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e467b67a38dba012b2c755b857fa2e6cb09395b2) perf(chat): selection lorebook button reads the selection on scroll only while text is selected ### 📊 Changes **1 file changed** (+16 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/SelectionLorebookButton.tsx` (+16 -6) </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`. ## Linked issue Closes #7640 ## Why this change - `SelectionLorebookButton` listens to every scroll in the app (capture on `window`) and to resize. Each event reads `window.getSelection()` in the next frame, and that read forces a layout. A package screen that scrolls over a mounted chat paid this on every frame, even with no text selected. On Slurp's Discover screen it cost 592 ms of forced layout when the screen opened, at 4× CPU throttle. ## What changed - `packages/client/src/components/chat/SelectionLorebookButton.tsx`: `selectionchange` records whether a non-collapsed selection exists and schedules the read as before. Scroll and resize schedule the read only while such a selection exists, so a selection that scrolls keeps its button in place. ## 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` ### Manual verification notes - Agent run: `pnpm install --frozen-lockfile` and `pnpm check` on this branch (based on `origin/staging` 154a33092) exited 0. - The cost was measured on a production install (headless Chromium, 390×844, 4× CPU throttle, CDP profiler). I did not measure this branch in a browser, and I did not click through text selection by hand. A reviewer should select text in a chat message, scroll the chat, and check that the button follows the selection and goes away when the selection collapses. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) 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) - No visual change. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved selection tracking so scrolling and resizing update the button only when text is selected. Selection-change and viewport event handlers are also cleaned up when no longer needed. <!-- 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-24 04:08:09 +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#7852
No description provided.