Repository navigation
Conversation
In Chrome, removing a stylesheet that contains @layer re-resolves every @Property rule in the document and restyles every element. Plugin sheets come and go with their views, so each close restyled the whole page about 1.5 s later. The app now registers its stylesheets' @Property rules with CSS.registerProperty before the first render and removes them from the CSS, which leaves nothing for a removal to re-resolve. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
|
Folded into #6148, which now includes both stylesheet insertion and removal fixes. |
ymichael
added a commit
that referenced
this pull request
Oct 27, 2026
## Human comments ## What was wrong Plugin stylesheets repeated Tailwind `@property` registrations and inherited theme variables on `:root`, so inserting a sheet restyled the entire document. Removing a layered plugin stylesheet also made Chrome re-resolve the host's CSS `@property` rules and restyle the whole page. Fixing only insertion or only the host registrations left the other trigger intact. Unconditionally stripping plugin CSS on the server also created version skew: a tab loaded before an update retains its old host CSS while fetching new plugin CSS. The old host lacks about 50 registrations and 330 theme variables supplied by the expanded host sheet. ## What changed This combines #6148 and #6149, rebased onto `origin/main` at `2f61afc227` (#6157). Conflict resolution preserved main's runtime-slot metadata, retired Git API migration-warning coverage, and this PR's CSS regression coverage; no CSS behavior changes were needed. - Generate the complete Tailwind registrations, fallback declarations and theme values into the host stylesheet. Strip only identical host-provided rules from plugin CSS; preserve different or unknown declarations. Plugin build artifacts remain complete and compatible with older servers. - Before the first app render, move the host's top-level CSS property registrations into `CSS.registerProperty()` and delete the equivalent CSS rules. Keep conflicting rules, rejected registrations and unreadable sheets. Keep the loader's existing attach/release lifecycle and 1.5-second removal grace period. - Make stripping opt-in from the app: preload, prefetch and stylesheet URLs carry `host-tailwind=<hash of generated host CSS>`. Both asset routes serve the complete original CSS for absent or mismatched markers. A future host CSS change gets a different marker automatically. Bundle hashes cover both CSS variants, and compressed response caches distinguish them. - Document the request behavior and stale-tab reproduction in `docs/debugging-and-qa.md`. No daemon wire changes or new CLI/SDK controls; browser, desktop and mobile use the same app loader. Script registrations take precedence over CSS `@property`; a plugin's conflicting registration can no longer override a host registration. No bundled plugin depends on that behavior. Browsers without `CSS.registerProperty` retain the CSS rules and fallback layer. ## How you verified ### Combined performance results The existing PR measurements below used the same 70-thread fixture (about 1,420 elements), Chrome at 1280×800, Performance-domain style duration and trace element counts, median of seven. The after column includes **both** changes. | Operation | Main | Combined | | --- | --- | --- | | Page open (sidebar + composer) | 71.5 ms / 3,785 elements | 44.4 ms / 1,579 elements | | Automations open / close | 88.7 / 83.1 ms | 45.0 / 45.6 ms | | Storage & retention open / close | 74.0 / 83.4 ms | 41.4 / 42.2 ms | | Plugin Guide open / close | 214.0 / 81.1 ms | 158.4 / 42.0 ms | | Remove Automations stylesheet | 26.0 ms / 1,162 elements | 12.6 ms / 78 elements | | Remove Storage & retention stylesheet | 27.7 ms / 1,162 elements | 9.2 ms / 78 elements | | Remove Plugin Guide stylesheet | 29.2 ms / 1,162 elements | 14.3 ms / 78 elements | | Remove Automations stylesheet, 16,000-element page | 63.9 ms / 16,006 elements | 35.6 ms / 0 elements | The prior insertion-only measurements were Automations 38.2 → 17.3 ms (1,234 → 86 elements), Plugin Guide 39.4 → 16.4 ms (1,234 → 86), and GitHub PR Status 35.7 → 3.5 ms (1,346 → 26). WebKit broadly restyles on sheet changes and showed no material improvement. Prior combined verification covered open/close/reopen, popover and dialog animations, spinners, the Automations toast, and compact drawer transitions in Chrome and WebKit. ### Stale tab across a server update Reproduced in real headless Chrome 155 at 1280×800 using main `efe987702b87ca4bfe9df905b4b63ede478e12c7`, then switching the same isolated server to the combined branch and opening Automations and Plugin Guide through their navigation buttons. **Test condition:** normal `AppUpdateHost` revision detection automatically reloads the tab. To exercise the requested client that has not received that update status yet, a local proxy held `/api/v1/system/app-update` at main's actual response and retained main's immutable app assets. All plugin metadata, JS and CSS came from the real switched server. No app CSS or plugin styles were injected into the tab. The stale tabs' `performance.timeOrigin` and `index-BR1pQoni.css` host URL stayed unchanged across the server switch. | View / observation | Unconditionally stripped server | Opt-in server, old tab | Opt-in server, fresh tab | | --- | --- | --- | --- | | Automations content | Matches fresh load | Matches fresh load, zero changed content pixels | Reference | | Plugin Guide heading's italic “bb” | **600**, missing `--font-weight-bold`; fresh load is **700** | **700**, variable present | **700** | | Guide stylesheet | Stripped despite old host | Complete, 56 `@property` rules and theme layer | Stripped, 0 `@property` rules and no `:root` | Before the fix, the Guide heading differed by 440 screenshot pixels. After the fix its heading matches, and the Guide's computed styles and element geometry match across the old and fresh tabs; tiny rasterization differences remain in scaled fixture strokes. Screenshots and observations are retained in the task evidence directory (`/tmp/bb-6148-evidence/`). Old-tab timestamps: before case `1792785386806`, after case `1792785387394.9`; both retained main's CSS. The fresh app adds `host-tailwind=90105b453d213b90e1c3f988b900bdc9fbb0a5f2677466f83df3227db69320f9`; the old app sends no marker. ### Regression coverage and checks - Extended the existing real asset-route test. An unmarked request failed on the unpatched branch because the response omitted the original registrations/theme. It now passes. Both hash and plugin-ID routes cover matching, absent and mismatched markers, interleaved gzip requests, and immutable caching. - Existing frontend lifecycle tests now verify the capability URL through preload, prefetch, attach, replacement and grace-period handling. Property-registry coverage from #6149 is included. - `pnpm exec turbo run lint typecheck --filter=@bb/app --filter=@bb/server --filter=@bb/plugin-build`: passed. - Focused Turbo app tests: **46 passed**. Focused Turbo server asset tests: **13 passed**. - Production `pnpm start:worktree` build: passed, including app, server, host daemon, SDK and bundled plugins. - `pnpm exec turbo run test --filter=@bb/plugin-build`: **235 passed, 1 skipped**. - [Full GitHub CI](https://github.com/get-bb/bb/actions/runs/40545551643) passed on rebased head `f501ca183c4c7fd0e6960c13169e2f817f5a47ba`: **47 successful checks, 4 conditional skips, zero failures or pending checks**. Skips: iOS, Android, Node Compatibility smoke, and Windows dependency warming. All executed checks passed on their first attempt. Local affected lint/typechecks, 46 app tests, 13 server asset tests, and 235 plugin-build tests also passed (1 plugin-build test skipped). > AGENT GENERATED --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
A plugin's stylesheet is removed 1.5 s after its last view closes (
apps/app/src/lib/plugin-css.ts, from #2002). In Chrome, removing any stylesheet that contains@layer, which every plugin sheet does, makes the browser re-resolve every CSS@propertyrule in the document. That restyles every element. The host app's own CSS always has@propertyrules (95 from Tailwind on main), so every plugin view close restyled the whole page.How the sheet is removed doesn't matter. Removing the
<link>, disabling it, settingmedia="not all", emptying a<style>, or dropping an adopted sheet all cost the same, about 58 ms at 16,000 elements. What matters is CSS@propertyanywhere in the document, combined with@layerin the removed sheet. Properties registered from script withCSS.registerProperty()take no part in the cascade, so removing a sheet doesn't re-resolve them.What changed
apps/app/src/lib/stylesheet-property-registry.ts:moveStylesheetPropertiesToRegistryregisters every top-level@propertyrule in the given sheets withCSS.registerProperty(), using the same name, syntax, inherits and initial value, and deletes the rule from its sheet.apps/app/src/main.tsxcalls it once before the first render, whenCSS.registerPropertyexists, while the DOM is still empty. The@supportsfallback layer for browsers without@propertystays in the CSS.Script registrations take precedence over
@property. A plugin sheet that registers one of the host's names with different descriptors can no longer override the host's registration while it is attached. No bundled plugin does this; every bundled registration is identical to the host's.Depends on #6148 for the plugin-view gains. On main, each plugin sheet carries its own
@propertyrules and redeclares Tailwind theme variables on:root. Removing either restyles the whole page by itself. #6148 removes both from served plugin sheets, and this PR removes the remaining trigger in the host. Each is independent and safe alone.How you verified
Dev instances on the same 70-thread fixture (about 1,420 elements), headless Chrome 1280×800, Performance-domain
RecalcStyleDurationand traceUpdateLayoutTree.elementCount, median of 7.Removing a plugin sheet from the open app (the same
<link>the loader removes):Opening and closing plugin views (route change, sheet insert or removal, and render; style recalc ms):
On main, every open and close includes one full-document restyle (largest single recalc 1,154–1,162 elements). With both PRs, the largest is 92–132 elements, except the Plugin Guide's own first render.
Page open (sidebar plus composer): main 71.5 ms / 3,785 elements restyled; this PR alone 54.1 ms / 2,600; #6148 43.6 ms / 1,585; both 44.4 ms / 1,579.
Larger page (16,000 elements, real host CSS and the Automations sheet as served by #6148): Chrome removal goes from 63.9 ms, restyling all 16,006 elements, to 35.6 ms, restyling none. WebKit costs about 62 ms for any sheet change either way, so it is unchanged.
Open, close and reopen of Automations on main, this PR, and both stacked, in Chrome and WebKit:
<link>is present on open and still present 0.4 s after close (grace period). It is gone by 2.6 s, back on reopen, and gone again after the second close.--tw-shadow: 0 0 #0000.@propertycount falls by exactly the host's 95, and to 0 on top of Avoid full-page restyles when plugin stylesheets load or unload #6148.Animations, both PRs stacked compared with main, all identical:
Tests and commands:
stylesheet-property-registry.test.tscovers four cases: registering and deleting rules, deleting identical duplicates while keeping a conflicting rule, keeping a rule the registry rejects, and skipping unreadable sheets.pnpm exec turbo run lint typecheck test --filter=@bb/app: 6,327 tests passed.pnpm exec turbo run build --filter=@bb/app --filter=@bb/bundled-plugins🤖 Generated with Claude Code