Skip to content

The agent that grows with you

fix(desktop): keep-alive hidden panes can no longer paint through

David Metcalfe816b360bdec2
diff --git a/apps/desktop/src/components/pane-shell/pane-visibility.test.ts b/apps/desktop/src/components/pane-shell/pane-visibility.test.ts
index b576689e70b..eabbbf1d065 100644
--- a/apps/desktop/src/components/pane-shell/pane-visibility.test.ts
+++ b/apps/desktop/src/components/pane-shell/pane-visibility.test.ts
@@ -1,7 +1,14 @@
+import { readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
import { PANE_HIDDEN_ATTR, queryAllVisible, queryVisible } from './pane-visibility'
+// The live stylesheet, read directly: the painting-contract test below must
+// validate the shipped rule, not a copy of it. Tests run with cwd =
+// apps/desktop (vitest projects root).
+const cssText = readFileSync(resolve(process.cwd(), 'src/styles.css'), 'utf8')
+
/**
* Inactive tabs stay mounted with their layout box intact, so they answer
* document-wide lookups exactly like the visible tab. These helpers are the one
@@ -28,3 +35,51 @@ describe('pane visibility lookups', () => {
expect(queryAllVisible(COMPOSER).map(el => el.id)).toEqual(['foreground'])
})
})
+
+describe('hidden pane painting contract', () => {
+ // The pane-level rule from styles.css that keeps a keep-alive hidden pane
+ // opaque to painting. Third-party widget scripts (Twitter's embed) render
+ // their card with an inline `visibility: visible`, which CSS would otherwise
+ // let paint through the pane's `visibility: hidden` over the active view
+ // (#79833). The rule forces every descendant to follow the pane's
+ // visibility. Extract it from the real stylesheet so this test validates the
+ // shipped rule — if the rule disappears, the contract is broken.
+ const paneBleedRule = (): string => {
+ // Anchored on the rule's own comment + selector, so reordering adjacent
+ // rules or reformatting unrelated CSS can't break the extraction.
+ const match = cssText.match(/\/\* Keep-alive hidden panes[\s\S]*?\[data-pane-hidden\] \* \{[\s\S]*?\}/)
+
+ expect(match).not.toBeNull()
+
+ return match![0]
+ }
+
+ afterEach(() => {
+ document.body.innerHTML = ''
+ document.head.querySelector('style[data-pane-bleed-rule]')?.remove()
+ })
+
+ it('keeps a descendant with inline visibility:visible from painting through a hidden pane', () => {
+ const style = document.createElement('style')
+
+ style.dataset.paneBleedRule = 'true'
+ style.textContent = paneBleedRule()
+ document.head.appendChild(style)
+
+ // What the reporter saw: the widget's rendered card (inline
+ // visibility:visible) nested inside a keep-alive pane (visibility:hidden).
+ document.body.innerHTML = `
+ <div data-pane-hidden style="visibility: hidden">
+ <div style="visibility: visible" id="leaky-card">card</div>
+ </div>
+ `
+
+ expect(getComputedStyle(document.getElementById('leaky-card')!).visibility).toBe('hidden')
+ })
+
+ it('does not affect a visible pane or an inline override outside one', () => {
+ document.body.innerHTML = `<div style="visibility: visible" id="live-card">card</div>`
+
+ expect(getComputedStyle(document.getElementById('live-card')!).visibility).toBe('visible')
+ })
+})
diff --git a/apps/desktop/src/styles.css b/apps/desktop/src/styles.css
index ca6046f9760..0135a891f77 100644
--- a/apps/desktop/src/styles.css
+++ b/apps/desktop/src/styles.css
@@ -3803,3 +3803,14 @@ html[data-hud-window] [data-slot='popover-content'] {
[data-hud-shell] [data-slot='composer-bounds'] *::-webkit-scrollbar {
display: none;
}
+
+/* Keep-alive hidden panes (see pane-visibility.ts) hide with `visibility:
+ hidden` so the layout box — and with it scroll positions — survives a tab
+ round-trip. But `visibility` is inherited-and-overridable: third-party
+ widget scripts (Twitter's embed injects its rendered card with an inline
+ `visibility: visible`) can paint through the hidden pane over the active
+ view (#79833). Force every descendant to follow the pane's visibility; an
+ author `!important` rule beats the widget's inline non-important style. */
+[data-pane-hidden] * {
+ visibility: inherit !important;
+}