feat: Keyborg ids should be unique for multiple bundles#75
Open
feat: Keyborg ids should be unique for multiple bundles#75
Conversation
Currently if a keyborg instance is created from different bundles they will have the same id since the counter is on the file scope. This PR updates the id generation so that it is unique for a global core instance
📊 Bundle size reportUnchanged fixtures
|
mshoho
reviewed
Feb 28, 2024
| } | ||
|
|
||
| // other bundles might have created keyborg instances before this one | ||
| while (current.refs[id]) { |
Member
There was a problem hiding this comment.
This implies that the other __keyborg has refs. And loops through it too.
Let's probably have something like this for createId():
private createId() {
const rnd = new Uint32Array(4);
crypto.getRandomValues(rnd);
return rnd.join('') + '|' + Date.now() + '|' + ++_lastId;
}
It has a pretty good chance to never collide...
Contributor
Author
There was a problem hiding this comment.
there's only one js thread, right? so they wouldn't loop through the global at the same time?
Member
There was a problem hiding this comment.
It's not about thread safety, it's about accessing black box internals assuming it's not a black box.
There was a problem hiding this comment.
Why not use a different prefix for the new version that is collision save:
k-num
Probably the same should be done for the core id just to get rid of the file scoped thing, and make it version agnostic
This was referenced Jun 20, 2025
3 tasks
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.

Currently if a keyborg instance is created from different bundles they will have the same id since the counter is on the file scope.
This PR updates the id generation so that it is unique for a global core instance