Skip to content

Commit bcc7caa

Browse files
committed
fix(houdini-utils): generate non-clashing IDs
1 parent b98c65b commit bcc7caa

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix(houdini-utils): generate non-clashing IDs",
4+
"packageName": "@fluentui-contrib/houdini-utils",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/houdini-utils/src/paint/fallback/fallbackPaintAnimation.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
FallbackAnimationState,
1313
PaintWorklet,
1414
} from '../../types';
15+
import { generateFallbackId } from './util/generateFallbackId';
1516

1617
const cannotDraw = {
1718
id: '',
@@ -24,8 +25,6 @@ const cannotDraw = {
2425
stop: () => {},
2526
};
2627

27-
let flairFallbackId = 0;
28-
2928
export const fallbackPaintAnimation = (
3029
targetEl: HTMLElement,
3130
paintWorklet: PaintWorklet,
@@ -36,13 +35,14 @@ export const fallbackPaintAnimation = (
3635
// eslint-disable-next-line no-restricted-globals
3736
targetDocument.defaultView ?? (window as Window & typeof globalThis);
3837

38+
const id = generateFallbackId();
3939
const state: FallbackAnimationState = {
4040
targetEl,
4141
targetWindow,
4242

4343
ctx: null,
4444
mode: 'to-data-url',
45-
id: `houdini-fallback-${++flairFallbackId}`,
45+
id: `${id}-houdini-fallback`,
4646
wrapper: null,
4747
running: false,
4848
resizeObserver: null,
@@ -52,7 +52,8 @@ export const fallbackPaintAnimation = (
5252
// Create a wrapper for us to store these elements in so we avoid
5353
// thrashing the DOM with appends.
5454
if (!state.wrapper) {
55-
const wrapperId = `houdini-fallback-wrapper-${flairFallbackId}`;
55+
const wrapperId = `${id}-houdini-fallback-wrapper`;
56+
5657
state.wrapper = appendWrapper(wrapperId, targetDocument.body);
5758
}
5859

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { generateFallbackId } from './generateFallbackId';
2+
3+
describe('generateFallbackId', () => {
4+
it('should generate IDs with correct prefix', () => {
5+
const id = generateFallbackId();
6+
expect(id).toMatch(/^f-/);
7+
});
8+
9+
it('should generate unique IDs', () => {
10+
const ids = new Set<string>();
11+
for (let i = 0; i < 1000; i++) {
12+
ids.add(generateFallbackId());
13+
}
14+
expect(ids.size).toBe(1000);
15+
});
16+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Generates a unique DOM ID for fallback animations.
3+
* Fast and simple implementation using timestamp + random suffix.
4+
*/
5+
export function generateFallbackId(): string {
6+
return `f-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 9)}`;
7+
}

0 commit comments

Comments
 (0)