Skip to content

Commit 0be1a7a

Browse files
committed
fix(animated-fab): add canvasContext caching (web)
1 parent b877fdc commit 0be1a7a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/components/FAB/utils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,17 @@ export const getExtendedFabStyle = ({
436436
return isV3 ? v3Extended : extended;
437437
};
438438

439+
let cachedContext: CanvasRenderingContext2D | null = null;
440+
439441
const getCanvasContext = () => {
440-
const fragment = document.createDocumentFragment();
441-
const canvas = document.createElement('canvas');
442+
if (cachedContext) {
443+
return cachedContext;
444+
}
442445

443-
fragment.appendChild(canvas);
446+
const canvas = document.createElement('canvas');
447+
cachedContext = canvas.getContext('2d');
444448

445-
return canvas.getContext('2d');
449+
return cachedContext;
446450
};
447451

448452
export const getLabelSizeWeb = (ref: MutableRefObject<HTMLElement | null>) => {

0 commit comments

Comments
 (0)