Skip to content

Conversation

@agliga
Copy link
Contributor

@agliga agliga commented Aug 18, 2025

There is a bug when you import keyboard trap on the server that it breaks.
This is because the observer is globally defined.
It should only break if you call "trap" on the server.
Added a check to only initialize the observer if window is defined.

@agliga agliga requested review from Copilot and ianmcburnie August 18, 2025 19:43
Copy link

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 bug in the keyboard trap component where importing the module would break on the server due to a globally defined MutationObserver. The fix adds a window check to conditionally initialize the observer only in browser environments.

  • Added conditional initialization of the MutationObserver based on window availability
  • Updated observer usage to handle null cases with optional chaining
  • Moved observer declaration to the top of the file for better organization

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@ianmcburnie ianmcburnie requested a review from saiponnada August 18, 2025 20:50
@agliga agliga merged commit 9ec46ee into master Aug 18, 2025
1 check passed
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.

3 participants