Skip to content

chore: drop canOverrideNativeFocus runtime probe#177

Open
layershifter wants to merge 1 commit into
microsoft:mainfrom
layershifter:perf/drop-ie9-focus-probe
Open

chore: drop canOverrideNativeFocus runtime probe#177
layershifter wants to merge 1 commit into
microsoft:mainfrom
layershifter:perf/drop-ie9-focus-probe

Conversation

@layershifter
Copy link
Copy Markdown
Member

@layershifter layershifter commented May 18, 2026

Summary

canOverrideNativeFocus was a feature-detection helper that temporarily reassigned HTMLElement.prototype.focus to a no-op, called .focus() on a synthetic button, and checked whether the override fired. The result was cached in the module-level _canOverrideNativeFocus flag and gated the details.isFocusedProgrammatically write inside setupFocusEvent.

The probe guarded against pre-IE9 environments where prototype-level focus overrides were ignored. Every browser keyborg currently supports honours the override, so the flag is effectively always true after the first call.

Drops:

  • the canOverrideNativeFocus function (~17 lines of synthetic-button-focus dance),
  • the module-level _canOverrideNativeFocus flag,
  • the lazy initialization branch inside setupFocusEvent.

The gated isFocusedProgrammatically write becomes unconditional:

// before
if (_canOverrideNativeFocus || data[LAST_FOCUSED_PROGRAMMATICALLY]) {
  details.isFocusedProgrammatically =
    target === data[LAST_FOCUSED_PROGRAMMATICALLY]?.deref();
  data[LAST_FOCUSED_PROGRAMMATICALLY] = undefined;
}

// after
details.isFocusedProgrammatically =
  target === data[LAST_FOCUSED_PROGRAMMATICALLY]?.deref();
data[LAST_FOCUSED_PROGRAMMATICALLY] = undefined;

Semantically identical when the override works, which is the only case still in scope.

Public API impact

None. canOverrideNativeFocus was module-private; _canOverrideNativeFocus was a module-private variable.

🤖 Generated with Claude Code

The `canOverrideNativeFocus` helper detected whether reassigning
`HTMLElement.prototype.focus` was respected by the browser. The check
was guarding against pre-IE9 behaviour where prototype overrides were
ignored.

Every browser keyborg currently supports honours the override, so the
`_canOverrideNativeFocus` flag is effectively always true after the
first call. Replace the conditional `details.isFocusedProgrammatically`
write with an unconditional one — semantically identical when the
override works, which is the only case we still ship for — and drop the
probe entirely.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
keyborg
All exports
3.974 kB
1.627 kB
3.765 kB
1.557 kB
-209 B
-70 B
keyborg
createKeyborg() & disposeKeyborg()
3.806 kB
1.586 kB
3.597 kB
1.514 kB
-209 B
-72 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
keyborg
KEYBORG_FOCUSIN constant
64 B
80 B
🤖 This report was generated against dfd7fe32327b37d8746c44aef6cebeda1ecc2397

@layershifter layershifter changed the title perf: drop canOverrideNativeFocus runtime probe chore: drop canOverrideNativeFocus runtime probe May 18, 2026
@layershifter layershifter marked this pull request as ready for review May 18, 2026 10:35
@layershifter layershifter requested review from a team and mshoho as code owners May 18, 2026 10:35
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.

2 participants