Skip to content

Commit

Permalink
Fix ssr by using typeof checks on global (#10775)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers authored Dec 18, 2024
1 parent cce74dd commit 8a08bde
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/common/src/hooks/useImageSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ declare global {
var IMAGE_CACHE: Set<string>
}

if (global) {
if (typeof global !== 'undefined') {
if (!global.IMAGE_CACHE) {
global.IMAGE_CACHE = new Set<string>()
}
}

const IMAGE_CACHE = global.IMAGE_CACHE
const IMAGE_CACHE =
typeof global !== 'undefined' ? global.IMAGE_CACHE : new Set<string>()

// Gets the width from a given image size, e.g. '150x150' => 150
const getWidth = (size: string) => {
Expand Down

0 comments on commit 8a08bde

Please sign in to comment.