Skip to content

Commit 8ed0331

Browse files
committed
fix: window reference on server
1 parent 8f2e64b commit 8ed0331

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/doom/src/runtime/components/Masonry.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import type MasonryLayout from 'masonry-layout'
1+
import type { Options } from 'masonry-layout'
22
import { useLayoutEffect, useRef, type HTMLAttributes } from 'react'
33

44
export interface MasonryProps extends HTMLAttributes<HTMLDivElement> {
5-
options?: MasonryLayout.Options
5+
options?: Options
6+
}
7+
8+
let MasonryLayout: typeof import('masonry-layout')
9+
10+
if (typeof window !== 'undefined') {
11+
MasonryLayout = (await import('masonry-layout')).default
612
}
713

814
export const Masonry = ({ options, ...props }: MasonryProps) => {
@@ -13,11 +19,7 @@ export const Masonry = ({ options, ...props }: MasonryProps) => {
1319
return
1420
}
1521

16-
// eslint-disable-next-line @typescript-eslint/no-require-imports
17-
const masonry = new (require('masonry-layout') as typeof MasonryLayout)(
18-
ref.current,
19-
options,
20-
)
22+
const masonry = new MasonryLayout!(ref.current, options)
2123

2224
return () => {
2325
masonry.destroy?.()

0 commit comments

Comments
 (0)