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

fix: make menu, popover, select ssr friendly #1660

Merged
merged 2 commits into from
Jun 16, 2023

Conversation

jinlee93
Copy link
Contributor

Summary:

  • wraps createportal used in the Menu, Popover, and Select components in a conditional checking for window
  • tested working with v12.2.0-alpha.2 release on running edu-stack locally
  • tried wrapping document.body in useEffect but still got ssr errors

Test Plan:

  • CI tests / new tests are not applicable
  • Manually tested my changes, and here are the details:
    • Create an alpha publish and try out in edu-stack or traject as a sanity check if changes affect build or deploy, or are breaking, such as token changes, widely used component updates, hooks changes, and major dependency upgrades.

@jinlee93 jinlee93 requested a review from a team June 15, 2023 23:16
</>
);
}
return null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried something like:

  const [container] = useState(() => {
    const el = document.createElement('div')
    return el
  })

  useEffect(() => {
    document.body.appendChild(container);
    return () => {
      document.body.removeChild(container)
    }
  }, [])

  return (
    <>{createPortal(<HeadlessMenu.Items {...optionProps} />, container)}</>
  );

but still got error along the lines of document is not defined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rather than finagling with this more I felt like checking for window was simpler and easier to understand

@codecov
Copy link

codecov bot commented Jun 15, 2023

Codecov Report

Merging #1660 (4bce6df) into next (bbee463) will decrease coverage by 0.09%.
The diff coverage is 66.66%.

@@            Coverage Diff             @@
##             next    #1660      +/-   ##
==========================================
- Coverage   93.30%   93.21%   -0.09%     
==========================================
  Files         222      222              
  Lines        2957     2963       +6     
  Branches      717      720       +3     
==========================================
+ Hits         2759     2762       +3     
- Misses        181      184       +3     
  Partials       17       17              
Impacted Files Coverage Δ
src/components/Menu/Menu.tsx 97.91% <66.66%> (-2.09%) ⬇️
src/components/Popover/Popover.tsx 91.89% <66.66%> (-2.40%) ⬇️
src/components/Select/Select.tsx 94.50% <66.66%> (-1.01%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@github-actions
Copy link

github-actions bot commented Jun 15, 2023

size-limit report 📦

Path Size
components 95.15 KB (+0.09% 🔺)
styles 36.54 KB (0%)

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

This approach seems reasonable and is along the lines of what the remix docs call out https://remix.run/docs/en/1.17.1/pages/gotchas#typeof-window-checks

@jinlee93 jinlee93 force-pushed the jlee/fixMenuPopoverSelectCreatePortal branch from 6498f81 to 4bce6df Compare June 16, 2023 20:18
@jinlee93
Copy link
Contributor Author

This approach seems reasonable and is along the lines of what the remix docs call out https://remix.run/docs/en/1.17.1/pages/gotchas#typeof-window-checks

Used typeof document !== 'undefined' as recommended by docs, and tested working with alpha v12.2.0-alpha.3

@jinlee93 jinlee93 merged commit eac8829 into next Jun 16, 2023
@jinlee93 jinlee93 deleted the jlee/fixMenuPopoverSelectCreatePortal branch June 16, 2023 20:25
@booc0mtaco booc0mtaco mentioned this pull request Jun 21, 2023
booc0mtaco added a commit that referenced this pull request Jun 21, 2023
## [12.2.0](v12.1.0...v12.2.0) (2023-06-21)


### Features

* deprecate color-other-eraser token ([#1640](#1640)) ([55a78e2](55a78e2))
* **Text:** add support for caption-md and caption-lg ([53fd4e0](53fd4e0))


### Bug Fixes

* allow all valid input types ([#1648](#1648)) ([e674741](e674741))
* **InputField:** fix alignment and color for required marker ([#1654](#1654)) ([1c3b1db](1c3b1db))
* make menu, popover, select ssr friendly ([#1660](#1660)) ([eac8829](eac8829))
* **Menu:** reset menu item hover and defer to popover ([#1653](#1653)) ([f329e4d](f329e4d))
* **ProgressBar:** align label and caption with design ([#1655](#1655)) ([9de0d6b](9de0d6b))
* **Tooltip:** use caption-lg for tooltip text ([f0772c7](f0772c7))
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.

1 participant