Skip to content

Allow customizing unique ID generation#1

Merged
kaznaan merged 1 commit intokaz/add-grid-4.3from
theop/uniqueId
Feb 14, 2026
Merged

Allow customizing unique ID generation#1
kaznaan merged 1 commit intokaz/add-grid-4.3from
theop/uniqueId

Conversation

@theop-luma
Copy link
Copy Markdown
Collaborator

@theop-luma theop-luma commented Nov 17, 2025

This let's app customize the algorithm that sets IDs, could be used to align ID generation between shapes & artifacts


Note

Introduces setUniqueIdGenerator to override ID generation globally and adds detailed docs/examples for createShapeId.

  • Utilities (@tldraw/utils):
    • ID Generation: Add setUniqueIdGenerator to override the global unique ID generator; keep uniqueId delegating to the pluggable impl.
    • Restore: Document and expose restoreUniqueId as public for reverting to the default generator.
    • Exports: Re-export setUniqueIdGenerator from packages/utils/src/index.ts.
  • Schema (tlschema):
    • Shape IDs: Expand JSDoc for createShapeId with examples and note about customizing via setUniqueIdGenerator.

Written by Cursor Bugbot for commit 5cb9cd0. This will update automatically on new commits. Configure here.

@theop-luma theop-luma changed the base branch from kaz/add-grid to kaz/add-grid-4.3 February 13, 2026 21:48
@cursor
Copy link
Copy Markdown

cursor Bot commented Feb 13, 2026

PR Summary

Medium Risk
Changing the global ID generator can affect uniqueness/collision behavior across all records if misused, though the default behavior is unchanged unless an app opts in.

Overview
Adds a new public API setUniqueIdGenerator in @tldraw/utils to let apps override the internal uniqueId() implementation, with restoreUniqueId() now documented/public for resetting back to the default generator.

Updates exports to expose the new setter, and refreshes createShapeId docs to reference this customization hook (plus minor doc/example tweaks).

Written by Cursor Bugbot for commit 054367a. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is ON. A Cloud Agent has been kicked off to fix the reported issue.

Comment thread packages/utils/src/lib/id.ts
@cursor
Copy link
Copy Markdown

cursor Bot commented Feb 13, 2026

Bugbot Autofix prepared fixes for 1 of the 1 bugs found in the latest run.

  • ✅ Fixed: setUniqueIdGenerator duplicates mockUniqueId implementation exactly
    • Changed mockUniqueId to delegate to setUniqueIdGenerator(fn) instead of directly assigning impl = fn, eliminating the code duplication.

Create PR

Or push these changes by commenting:

@cursor push e484e66c7a
Preview (e484e66c7a)
diff --git a/packages/utils/api-report.api.md b/packages/utils/api-report.api.md
--- a/packages/utils/api-report.api.md
+++ b/packages/utils/api-report.api.md
@@ -408,7 +408,7 @@
 }>;
 export { Required_2 as Required }
 
-// @internal
+// @public
 export function restoreUniqueId(): void;
 
 // @public
@@ -448,6 +448,9 @@
 // @internal
 export function setInSessionStorage(key: string, value: string): void;
 
+// @public
+export function setUniqueIdGenerator(fn: (size?: number) => string): void;
+
 // @internal
 export function sleep(ms: number): Promise<void>;
 

diff --git a/packages/utils/src/lib/id.ts b/packages/utils/src/lib/id.ts
--- a/packages/utils/src/lib/id.ts
+++ b/packages/utils/src/lib/id.ts
@@ -105,7 +105,7 @@
  * @internal
  */
 export function mockUniqueId(fn: (size?: number) => string) {
-	impl = fn
+	setUniqueIdGenerator(fn)
 }
 
 /**

@kaznaan kaznaan merged commit 44e3e86 into kaz/add-grid-4.3 Feb 14, 2026
5 of 10 checks passed
@kaznaan
Copy link
Copy Markdown
Collaborator

kaznaan commented Feb 14, 2026

oops, this has a build error. I'll revert my change and please fix build error.

kaznaan added a commit that referenced this pull request Feb 14, 2026
This reverts commit 44e3e86, reversing
changes made to 7cd5fe5.
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