Skip to content

fix: use unique IDs to prevent instance collisions across bundles#126

Open
layershifter wants to merge 4 commits intomicrosoft:mainfrom
layershifter:fix/unique-instance-ids
Open

fix: use unique IDs to prevent instance collisions across bundles#126
layershifter wants to merge 4 commits intomicrosoft:mainfrom
layershifter:fix/unique-instance-ids

Conversation

@layershifter
Copy link
Member

@layershifter layershifter commented Mar 4, 2026

Summary

  • Replaces the module-scoped _lastId counter with crypto.getRandomValues() to generate unique instance IDs
  • When multiple bundles include keyborg on the same page, they each had their own _lastId starting at 0, causing ID collisions in the shared window.__keyborg.refs map
  • With random IDs, each instance is guaranteed unique regardless of how many bundles coexist
  • Uses crypto.getRandomValues() (not crypto.randomUUID()) to support Edge 84+, Firefox 75+, Chrome 84+, Safari 14.1+

Closes #99
Supersedes #75 and #104

Test plan

  • npm run build passes
  • npm run lint passes
  • All existing Playwright tests pass (10/10)

🤖 Generated with Claude Code

layershifter and others added 2 commits March 4, 2026 11:58
Adds the "exports" field to prevent deep importing of internal modules.
Closes microsoft#21.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the module-scoped _lastId counter with crypto.getRandomValues()
to generate unique IDs. This prevents ID collisions when multiple bundles
include keyborg on the same page.

Closes microsoft#99

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@layershifter layershifter requested review from a team and mshoho as code owners March 4, 2026 11:06
layershifter and others added 2 commits March 4, 2026 12:12
The test doesn't accurately simulate the multi-bundle scenario described
in the issue since it uses the same module scope for both instances.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
keyborg
All exports
6.991 kB
2.077 kB
7.121 kB
2.155 kB
130 B
78 B
keyborg
createKeyborg() & disposeKeyborg()
6.755 kB
2.028 kB
6.885 kB
2.105 kB
130 B
77 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
keyborg
KEYBORG_FOCUSIN constant
64 B
80 B
🤖 This report was generated against 4658ddcd049caa75a25c67ed801c1d19229f5353

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.

Keyborg instances are overriden when multiple code instances are deployed on the same site

1 participant