Uh oh!
There was an error while loading. Please reload this page.
Fix useDynamicTextareaHeight initial render with slots - #3196
Conversation
🦋 Changeset detectedLatest commit: 1026d29 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
josepmartins
commented
Apr 20, 2023
Het @iansan5653, there are some linting errors with unnecessary dependencies and the UseEffect declaration. Can you take a look at those? 🙏 |
size-limit report 📦
|
iansan5653
commented
Apr 20, 2023
Should be good now! |
josepmartins
left a comment
There was a problem hiding this comment.
LGMT! I adding @rezrah as a reviewer as well 🙏
colebemis
commented
Apr 24, 2023
@iansan5653 Is this still necessary with the new implementation of slots? https://github.com/primer/react/blob/main/src/hooks/useSlots.ts |
iansan5653
commented
Apr 26, 2023
Probably not - let's keep an eye on it after we update dotcom and close this out if it resolves itself. |
iansan5653
commented
May 1, 2023
@colebemis it looks like we haven't shipped slots updates for |
joshblack
commented
May 22, 2023
bump @colebemis wanted to check in if this was something we still need to include in the release or if it's already been addressed by the slots updates mentioned above 👀 |
😕 Actually I think I was wrong - doesn't look like |
colebemis
left a comment
There was a problem hiding this comment.
Thanks for your patience! These changes look good to me 👍
Uh oh!
There was an error while loading. Please reload this page.
Sometimes,
useDynamicTextareaHeightcannot determine what the height of the textarea should be on initial render. This can be seen in Projects in the single-select editor dialog, which is contained inside aDialogv2 component:Screen.Recording.2023-04-19.at.3.03.18.PM.mov
Notice how the description field initially has extra height, but then collapses down to the correct height after the user starts typing. This is jarring and annoying.
It appears that this is caused by an interaction with the 'slots' pattern where the input is initially hidden on first render, then becomes visible after the layout effect has already run. The layout effect does not rerun when the slots resolve, causing the height to be incorrectly calculated on first render.
We could update the effect to re-run on every render, but because it sets state this would cause a cyclical infinite render loop. Alternatively, we could change the effect to a regular effect (non-layout) which would cause it to always be correct, but this CSS update in an effect would cause distracting flashes when not using the slots pattern.
So this is a hacky workaround to resolve issues with slots, which is itself a hacky workaround: we run a regular effect in addition to a layout effect on first render, then only layout effects from then on.