Skip to content

Avoid full-page restyles when plugin stylesheets load or unload - #6148

Merged
ymichael merged 6 commits into
mainfrom
bb/plugin-css-animation-properties-thr_yvsvx8anai
Oct 27, 2026
Merged

ymichael merged 6 commits into
mainfrom
bb/plugin-css-animation-properties-thr_yvsvx8anai

Conversation

@ymichael

@ymichael ymichael commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

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 Keep plugin stylesheet removal from restyling the whole page #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 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

@ymichael
ymichael force-pushed the bb/plugin-css-animation-properties-thr_yvsvx8anai branch from de38101 to 3c0c256 Compare October 23, 2026 20:00
@ymichael ymichael changed the title Stop plugin stylesheets from restyling the whole page on insert Avoid full-page restyles when plugin stylesheets load or unload Oct 23, 2026
ymichael and others added 6 commits October 27, 2026 09:53
…bles to plugin sheets

Inserting a plugin stylesheet restyled the whole document in Chrome for two
reasons: every sheet carried @Property registrations (any @Property in an
inserted sheet invalidates every element), and every sheet redeclared
Tailwind theme variables on :root (inherited, so every element recomputes).
All of them duplicated what the host already declares.

plugin-build now generates every registration and theme variable its
Tailwind input can emit, the app loads that sheet once with its own CSS,
and plugin builds drop the identical registrations, their fallback
declarations and the identical theme variables.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Its only utility, line-clamp-2, passed 1 KiB because tw-animate's
registrations rode along in every plugin sheet. They now come from the host.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… at build time

Stripping at build time made a dist built with this bb rely on host
registrations an older bb does not make, and an older bb checks only the
SDK major and the author's engines ranges, so it would load such a bundle
unstyled. plugin-build now emits the full sheet again, byte-identical to
before, and the server removes the rules its own app already provides when
it loads the bundle. Older bundles get the same treatment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
@ymichael
ymichael force-pushed the bb/plugin-css-animation-properties-thr_yvsvx8anai branch from 3c0c256 to f501ca1 Compare October 27, 2026 16:54
@ymichael
ymichael merged commit c087372 into main Oct 27, 2026
53 checks passed
@ymichael
ymichael deleted the bb/plugin-css-animation-properties-thr_yvsvx8anai branch October 27, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant