react icon indicating copy to clipboard operation
react copied to clipboard

Portal is not ssr compat - accesses `document` during render

Open mattcosta7 opened this issue 2 years ago • 10 comments

Description

When using InlineAutocomplete we inherit usage of <Portal /> rendering on page load.

I think the issue occurs because <Portal> calls document.createElement and createPortal with a ref to an element that can't be created.

https://github.com/primer/react/blob/500e529df47ae5def4bf5cedc55fc099251c25a1/src/Portal/Portal.tsx#L68

we should avoid these apis in render in portal (which creates a div on every render) and rely on other mechanisms to sync it

In addition to this, it renders an _Autocomplette which uses useCombobox which calls useLayoutEffect resulting in a call to console.error on the server - https://github.com/primer/react/blob/500e529df47ae5def4bf5cedc55fc099251c25a1/src/drafts/hooks/useCombobox.ts#L141-L157

Steps to reproduce

Atempt to SSR an app that uses InlineAutocomplete

Version

latest

Browser

No response

mattcosta7 avatar Sep 08 '23 18:09 mattcosta7

@mattcosta7 thanks for filing and for putting up some PRs! Are you still looking into a solve, or would you like support? If the latter, can you also give us some info on whether this is blocking a particular product feature?

lesliecdubs avatar Sep 11 '23 22:09 lesliecdubs

@mattcosta7 thanks for filing and for putting up some PRs! Are you still looking into a solve, or would you like support? If the latter, can you also give us some info on whether this is blocking a particular product feature?

I don't think I'll have time , but I don't believe it's blocking anything!

mattcosta7 avatar Sep 11 '23 22:09 mattcosta7

Thanks, copy that. We'll move this to the backlog for now, but happy to reassess priority at any point as needed.

lesliecdubs avatar Sep 12 '23 00:09 lesliecdubs

Hi! This issue has been marked as stale because it has been open with no activity for 180 days. You can comment on the issue or remove the stale label to keep it open. If you do nothing, this issue will be closed in 7 days.

github-actions[bot] avatar Mar 10 '24 01:03 github-actions[bot]

not stale

mattcosta7 avatar Mar 11 '24 15:03 mattcosta7

Hi! This issue has been marked as stale because it has been open with no activity for 180 days. You can comment on the issue or remove the stale label to keep it open. If you do nothing, this issue will be closed in 7 days.

github-actions[bot] avatar Sep 07 '24 16:09 github-actions[bot]