fix(utils): avoid id collisions in InitIDGenerator (preserve deterministic behavior)#7540
fix(utils): avoid id collisions in InitIDGenerator (preserve deterministic behavior)#7540kacemabidi12 wants to merge 2 commits intomermaid-js:developfrom
Conversation
… for compatibility
|
✅ Deploy Preview for mermaid-js ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@mermaid-js/examples
mermaid
@mermaid-js/layout-elk
@mermaid-js/layout-tidy-tree
@mermaid-js/mermaid-zenuml
@mermaid-js/parser
@mermaid-js/tiny
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7540 +/- ##
==========================================
- Coverage 3.34% 3.34% -0.01%
==========================================
Files 524 524
Lines 55256 55271 +15
Branches 795 795
==========================================
Hits 1850 1850
- Misses 53406 53421 +15
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
I made a small change (InitIDGenerator) and added unit tests. The CI failure looks unrelated because the E2E job failed while uploading screenshots to Argos:
The Argos upload error caused the Cypress job to crash and produced "Could not find Cypress test run results".
The change itself only affects unit tests in packages/mermaid and shouldn't impact visual E2E tests. |
This PR fixes a rare bug in ID generation.
Before, the non-deterministic generator used Date.now() directly, so if several IDs were created within the same millisecond, duplicates could happen. To fix this, the generator now uses the timestamp plus a small counter for calls made in the same millisecond. This keeps the IDs unique.
The deterministic generator was not changed. It still starts from seed.length so existing behavior and tests stay the same.
Files changed:
Why?
Behavior notes:
Tests:
-- uniqueness of non-deterministic IDs when generating many IDs quickly
-- deterministic ID generation increasing by 1 starting from seed.length
Local testing: