Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix(houdini-utils): generate non-clashing IDs",
"packageName": "@fluentui-contrib/houdini-utils",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
FallbackAnimationState,
PaintWorklet,
} from '../../types';
import { generateFallbackId } from './util/generateFallbackId';

const cannotDraw = {
id: '',
Expand All @@ -24,8 +25,6 @@ const cannotDraw = {
stop: () => {},
};

let flairFallbackId = 0;

export const fallbackPaintAnimation = (
targetEl: HTMLElement,
paintWorklet: PaintWorklet,
Expand All @@ -36,13 +35,14 @@ export const fallbackPaintAnimation = (
// eslint-disable-next-line no-restricted-globals
targetDocument.defaultView ?? (window as Window & typeof globalThis);

const id = generateFallbackId();
const state: FallbackAnimationState = {
targetEl,
targetWindow,

ctx: null,
mode: 'to-data-url',
id: `houdini-fallback-${++flairFallbackId}`,
id: `${id}-houdini-fallback`,
wrapper: null,
running: false,
resizeObserver: null,
Expand All @@ -52,7 +52,8 @@ export const fallbackPaintAnimation = (
// Create a wrapper for us to store these elements in so we avoid
// thrashing the DOM with appends.
if (!state.wrapper) {
const wrapperId = `houdini-fallback-wrapper-${flairFallbackId}`;
const wrapperId = `${id}-houdini-fallback-wrapper`;

state.wrapper = appendWrapper(wrapperId, targetDocument.body);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { generateFallbackId } from './generateFallbackId';

describe('generateFallbackId', () => {
it('should generate IDs with correct prefix', () => {
const id = generateFallbackId();
expect(id).toMatch(/^f-/);
});

it('should generate unique IDs', () => {
const ids = new Set<string>();
for (let i = 0; i < 1000; i++) {
ids.add(generateFallbackId());
}
expect(ids.size).toBe(1000);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Generates a unique DOM ID for fallback animations.
* Fast and simple implementation using timestamp + random suffix.
*/
export function generateFallbackId(): string {
return `f-${Date.now().toString(36)}-${Math.random()
.toString(36)
.slice(2, 9)}`;
}