Skip to content

Conversation

@JounQin
Copy link
Member

@JounQin JounQin commented Dec 31, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Fixed server-side rendering window reference errors in the Masonry component.
  • Enhancements

    • Masonry is now loaded only on the client to prevent SSR issues.
    • Item wrappers include a generic masonry-item class so layout selection and item placement are more reliable.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings December 31, 2025 08:08
@changeset-bot
Copy link

changeset-bot bot commented Dec 31, 2025

🦋 Changeset detected

Latest commit: d714b19

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@alauda/doom Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Signed-off-by: JounQin <admin@1stg.me>
@coderabbitai
Copy link

coderabbitai bot commented Dec 31, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Replaces a server-side require of Masonry with a browser-only dynamic import to avoid a server-side window reference, updates the Masonry options type, and adds a .masonry-item CSS class to Overview-rendered items. Also adds a changeset entry documenting the fix.

Changes

Cohort / File(s) Summary
Changeset metadata
\.changeset/lazy-crabs-itch.md
Adds a patch changeset documenting "fix: window reference on server".
Masonry component
packages/doom/src/runtime/components/Masonry.tsx
Replaces static/require instantiation with client-only dynamic import of MasonryLayout; uses non-null assertion for construction and changes option type from MasonryLayout.Options to Options from masonry-layout.
Overview component
packages/doom/src/runtime/components/Overview.tsx
Changes Masonry itemSelector from a scoped class to .masonry-item and adds that class to each item wrapper in the rendered output.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant SSR as Server (SSR)
  participant Browser as Client (Browser)
  participant MasonryComp as Masonry component
  participant MasonryLib as MasonryLayout (lib)

  Note over SSR,MasonryComp: During server render
  SSR->>MasonryComp: render()
  MasonryComp-->>SSR: avoid instantiating Masonry (no window usage)

  Note over Browser,MasonryComp: On client hydration
  Browser->>MasonryComp: hydrate / mount
  MasonryComp->>MasonryLib: dynamic import() (async)
  MasonryLib-->>MasonryComp: resolves with MasonryLayout
  MasonryComp->>MasonryLib: new MasonryLayout(element, options)
  MasonryComp-->>Browser: layout applied to `.masonry-item` elements
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

bug

Poem

🐰 I hopped from server to browser light,
Lazy-loaded bricks stacking just right,
No window crash in midnight debug,
I nudge each item — hop, shimmy, snug.
🎨✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: window reference on server' directly matches the changeset message and addresses the core issue of fixing window reference problems in server-side code, accurately reflecting the main purpose of the changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26f2b9a and d714b19.

📒 Files selected for processing (1)
  • packages/doom/src/runtime/components/Overview.tsx
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{js,ts,tsx,jsx,json,yml,yaml,md}

📄 CodeRabbit inference engine (AGENTS.md)

Format code with Prettier according to the project's Prettier configuration

Files:

  • packages/doom/src/runtime/components/Overview.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript strict mode for type safety

Files:

  • packages/doom/src/runtime/components/Overview.tsx
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Follow ESLint rules defined in eslint.config.js

Files:

  • packages/doom/src/runtime/components/Overview.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Build and Lint with Node.js 24 on ubuntu-latest
  • GitHub Check: Build and Lint with Node.js 20 on ubuntu-latest
  • GitHub Check: Build and Lint with Node.js 22 on ubuntu-latest
  • GitHub Check: Build and Lint with Node.js 24 on ubuntu-latest
  • GitHub Check: Build and Lint with Node.js 20 on ubuntu-latest
  • GitHub Check: Build and Lint with Node.js 22 on ubuntu-latest
🔇 Additional comments (2)
packages/doom/src/runtime/components/Overview.tsx (2)

235-238: LGTM! Proper class addition maintains styling compatibility.

Adding the masonry-item class while preserving classes.overviewGroup ensures the Masonry selector (line 54) targets these items correctly while maintaining existing styles. The implementation is clean and maintains backward compatibility.


53-56: Selector change is consistent with added class.

The change from a scoped CSS module class to the generic .masonry-item selector aligns with the class added to item wrappers (line 236). This approach avoids server-side CSS module resolution issues that can cause window reference errors. The Masonry component correctly handles this selector via the options parameter and initializes only on the client side.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 31, 2025

Open in StackBlitz

yarn add https://pkg.pr.new/@alauda/doom@234.tgz
yarn add https://pkg.pr.new/@alauda/doom-export@234.tgz

commit: d714b19

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a server-side rendering issue by preventing the masonry-layout library from being accessed on the server where the window object is unavailable. The solution conditionally imports the library only in browser environments.

  • Replaces synchronous require() with conditional top-level await import() guarded by window check
  • Updates type imports to use named Options type instead of namespace access
  • Adds non-null assertion when instantiating MasonryLayout since it's guaranteed to exist in browser context

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/doom/src/runtime/components/Masonry.tsx Conditionally imports masonry-layout only in browser environments to prevent server-side window reference errors
.changeset/lazy-crabs-itch.md Documents the fix for window reference on server

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f2e64b and 26f2b9a.

📒 Files selected for processing (2)
  • .changeset/lazy-crabs-itch.md
  • packages/doom/src/runtime/components/Masonry.tsx
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{js,ts,tsx,jsx,json,yml,yaml,md}

📄 CodeRabbit inference engine (AGENTS.md)

Format code with Prettier according to the project's Prettier configuration

Files:

  • packages/doom/src/runtime/components/Masonry.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript strict mode for type safety

Files:

  • packages/doom/src/runtime/components/Masonry.tsx
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Follow ESLint rules defined in eslint.config.js

Files:

  • packages/doom/src/runtime/components/Masonry.tsx
🔇 Additional comments (4)
.changeset/lazy-crabs-itch.md (1)

1-5: LGTM! Changeset format is correct.

The changeset follows the standard format with appropriate patch version type for this bug fix.

packages/doom/src/runtime/components/Masonry.tsx (3)

1-1: LGTM! Type-only import is safe.

The type-only import is correctly used and will be erased at runtime, preventing any server-side issues.


5-6: LGTM! Type update is correct.

The type change from MasonryLayout.Options to Options is consistent with the new import and maintains type safety.


22-22: Non-null assertion relies on top-level await completion.

The non-null assertion MasonryLayout! assumes the top-level await completed successfully. While useLayoutEffect only runs on the client where the import should be complete, this creates a tight coupling to the top-level await pattern.

The refactor suggested in the previous comment (moving the import into the effect) would eliminate the need for this assertion and handle the async nature more explicitly.

Based on coding guidelines, ensure this passes TypeScript strict mode checks.

@JounQin JounQin merged commit 0be4926 into main Dec 31, 2025
14 checks passed
@JounQin JounQin deleted the fix/window_reference branch December 31, 2025 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants