Skip to content

Commit

Permalink
omit properties of DOMRect from getComputedWithCache
Browse files Browse the repository at this point in the history
  • Loading branch information
canalun committed Feb 16, 2024
1 parent 2e9f87b commit 2384c33
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/game/getComputedStyleWithCache.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// getComputedStyle() is expensive, so we should cache the result.
// We can assume that the style of an element doesn't change, because the page is frozen.
// We can assume that the style of an element doesn't change, except for DOMRect-related,
// because the page is frozen.
const styleCache = new Map<Element, CSSStyleDeclaration>()
export function getComputedStyleWithCache(
element: Element
): CSSStyleDeclaration {
): Omit<
CSSStyleDeclaration,
keyof ReturnType<typeof Element.prototype.getBoundingClientRect>
> {
const cache = styleCache.get(element)
if (cache) {
return cache
Expand Down

0 comments on commit 2384c33

Please sign in to comment.