-
Notifications
You must be signed in to change notification settings - Fork 538
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 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 |
Het @iansan5653, there are some linting errors with unnecessary dependencies and the UseEffect declaration. Can you take a look at those? 🙏 |
size-limit report 📦
|
Should be good now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT! I adding @rezrah as a reviewer as well 🙏
@iansan5653 Is this still necessary with the new implementation of slots? https://github.com/primer/react/blob/main/src/hooks/useSlots.ts |
Probably not - let's keep an eye on it after we update dotcom and close this out if it resolves itself. |
@colebemis it looks like we haven't shipped slots updates for |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patience! These changes look good to me 👍
Sometimes,
useDynamicTextareaHeight
cannot 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 aDialog
v2 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.