Skip to content

Improve page observer performance - #10318

Merged
fregante merged 4 commits into
mainfrom
claude/kodok-adopted-sheets
Oct 25, 2026
Merged

fregante merged 4 commits into
mainfrom
claude/kodok-adopted-sheets

Conversation

@fregante

@fregante fregante commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Created by Claude Kodok, will be reviewed by @fregante first.

Registers the selector observer styles as constructed stylesheets instead of appending a <style> tag per call, falling back to the old tag where content scripts can't access adoptedStyleSheets (Firefox <153). Identical styles (e.g. a feature initialized again after navigation) share one stylesheet, removed once its last observer aborts. Also warns in the console when the active stylesheet count reaches 50, 100, etc., once per milestone.

Part of #7777

Test URLs

Not feature-specific: affects every feature using the selector observer, e.g. https://github.com/refined-github/refined-github

Checked

  • Logged out only, on a mocked github.com page in headless Chromium 141: same number of stylesheets as main, no page errors in 5 runs
  • Content script use of adoptedStyleSheets verified in Chrome 141 with a throwaway extension

Not checked

  • Stylesheet deduplication: type-checked only, not run in a browser
  • Logged in
  • Firefox and Safari

Part of #7777

Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added the meta Related to Refined GitHub itself label Oct 23, 2026
@fregante fregante changed the title Meta: Register selector observer styles via adoptedStyleSheets Improve page observer performance Oct 25, 2026
@fregante fregante added enhancement and removed meta Related to Refined GitHub itself labels Oct 25, 2026
@fregante
fregante marked this pull request as ready for review October 25, 2026 11:31
Comment on lines +73 to +74
let style = styles.get(cssText);
if (!style) {

@fregante fregante Oct 25, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This deduplication logic should fix:

Repro:

  1. open PR
  2. navigate across its tabs

Before

Image

After

Image

@fregante
fregante merged commit 3705f79 into main Oct 25, 2026
21 checks passed
@fregante
fregante deleted the claude/kodok-adopted-sheets branch October 25, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

selector-observer <style> rules pile up on every soft navigation, slowing typing on PR pages

2 participants