Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/lazy-crabs-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alauda/doom": patch
---

fix: window reference on server
16 changes: 9 additions & 7 deletions packages/doom/src/runtime/components/Masonry.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import type MasonryLayout from 'masonry-layout'
import type { Options } from 'masonry-layout'
import { useLayoutEffect, useRef, type HTMLAttributes } from 'react'

export interface MasonryProps extends HTMLAttributes<HTMLDivElement> {
options?: MasonryLayout.Options
options?: Options
}

let MasonryLayout: typeof import('masonry-layout')

if (typeof window !== 'undefined') {
MasonryLayout = (await import('masonry-layout')).default
}

export const Masonry = ({ options, ...props }: MasonryProps) => {
const ref = useRef<HTMLDivElement>(null)

Check warning on line 15 in packages/doom/src/runtime/components/Masonry.tsx

View workflow job for this annotation

GitHub Actions / Build and Lint with Node.js 22 on ubuntu-latest

Ref variables should have names ending with 'Ref', e.g., 'inputRef'

Check warning on line 15 in packages/doom/src/runtime/components/Masonry.tsx

View workflow job for this annotation

GitHub Actions / Build and Lint with Node.js 20 on ubuntu-latest

Ref variables should have names ending with 'Ref', e.g., 'inputRef'

Check warning on line 15 in packages/doom/src/runtime/components/Masonry.tsx

View workflow job for this annotation

GitHub Actions / Build and Lint with Node.js 24 on ubuntu-latest

Ref variables should have names ending with 'Ref', e.g., 'inputRef'

Check warning on line 15 in packages/doom/src/runtime/components/Masonry.tsx

View workflow job for this annotation

GitHub Actions / Build and Lint with Node.js 22 on ubuntu-latest

Ref variables should have names ending with 'Ref', e.g., 'inputRef'

Check warning on line 15 in packages/doom/src/runtime/components/Masonry.tsx

View workflow job for this annotation

GitHub Actions / Build and Lint with Node.js 20 on ubuntu-latest

Ref variables should have names ending with 'Ref', e.g., 'inputRef'

Check warning on line 15 in packages/doom/src/runtime/components/Masonry.tsx

View workflow job for this annotation

GitHub Actions / Build and Lint with Node.js 24 on ubuntu-latest

Ref variables should have names ending with 'Ref', e.g., 'inputRef'

useLayoutEffect(() => {
if (!ref.current) {
return
}

// eslint-disable-next-line @typescript-eslint/no-require-imports
const masonry = new (require('masonry-layout') as typeof MasonryLayout)(
ref.current,
options,
)
const masonry = new MasonryLayout!(ref.current, options)

return () => {
masonry.destroy?.()
Expand Down
7 changes: 5 additions & 2 deletions packages/doom/src/runtime/components/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const getChildLink = (
}

const masonryOptions = {
itemSelector: `.${classes.overviewGroup}`,
itemSelector: `.masonry-item`,
gutter: 16,
}

Expand Down Expand Up @@ -232,7 +232,10 @@ export function Overview(props: {

<Masonry className={classes.overviewGroups} options={masonryOptions}>
{group.items.map((item) => (
<div className={classes.overviewGroup} key={item.link}>
<div
className={`${classes.overviewGroup} masonry-item`}
key={item.link}
>
<h3>
<Link href={item.link} {...renderInlineMarkdown(item.text)} />
</h3>
Expand Down
Loading