Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support ssr #30

Merged
merged 1 commit into from
Mar 6, 2025
Merged

feat: support ssr #30

merged 1 commit into from
Mar 6, 2025

Conversation

zyliang96
Copy link

@zyliang96 zyliang96 commented Mar 4, 2025

修复SSR下使用组件报错的问题

@@ -374,7 +374,7 @@ const Overlay = React.forwardRef<HTMLDivElement, OverlayProps>((props, ref) => {
// - react17 中,如果弹窗 mousedown 阻止了 e.stopPropagation(), 那么 document 就不会监听到事件,因为事件冒泡到挂载节点 rootElement 就中断了。
// - https://reactjs.org/blog/2020/08/10/react-v17-rc.html#changes-to-event-delegation
useListener(
document,
typeof document !== 'undefined' ? document : null,

Choose a reason for hiding this comment

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

useListener 监听的对象是 null 是否还有意义?是否更合理的方式应该是没有 document 的情况下就不监听了

Choose a reason for hiding this comment

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

下同

Copy link
Author

Choose a reason for hiding this comment

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

没有的情况在useListener 的具体实现里已经存在了,这里不能动态的设置hooks方法吧,react的hooks按顺序存储,不能没有document的情况下就不执行吧?

Choose a reason for hiding this comment

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

你说的有道理

@@ -374,7 +374,7 @@ const Overlay = React.forwardRef<HTMLDivElement, OverlayProps>((props, ref) => {
// - react17 中,如果弹窗 mousedown 阻止了 e.stopPropagation(), 那么 document 就不会监听到事件,因为事件冒泡到挂载节点 rootElement 就中断了。
// - https://reactjs.org/blog/2020/08/10/react-v17-rc.html#changes-to-event-delegation
useListener(
document,
typeof document !== 'undefined' ? document : null,

Choose a reason for hiding this comment

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

你说的有道理

@zyliang96 zyliang96 merged commit b5414a4 into master Mar 6, 2025
2 of 4 checks 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.

2 participants