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: SC-59775 fix nested select height after long render #1084

Merged
merged 4 commits into from
Oct 25, 2024

Conversation

0ces
Copy link
Contributor

@0ces 0ces commented Oct 21, 2024

Issue: when rendering a SelectField in a GridTable with no nested rows the select renders with the correct height, when updating the table to have nested rows the select field will fail calculating the new correct height, this change adds another delayed called that gives a better chance of having enough time for GridTable finishing the rendering so that useGrowingTextField will get the correct value.

@stephenh
Copy link
Contributor

@0ces since we don't have a unit test for this, can you record a screenshare of the before/after behavior? Might help maintainers know how to not break this going forward, if they git blame the code and come back to this PR in the future.

@@ -42,6 +42,8 @@ export function useGrowingTextField({ inputRef, inputWrapRef, value, disabled }:
return;
}
onHeightChange();
// This is a hack to re-measure the height of the textarea after all the content has been rendered (i.e. after multiple GridTable children have been rendered)
Copy link
Contributor

Choose a reason for hiding this comment

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

@0ces just curious, but is this only an issue in virtualized tables, or just any GridTable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stephenh I think only in virtualized tables, it happens when the columns change (remove/hide a column) and the tables changes from not grouped to grouped, I'll have a PR that solves the bug in our front-end by not changing the column when the table gets grouped.

Copy link
Contributor

Choose a reason for hiding this comment

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

@0ces so I'm not following if (when a column is hidden/changed from grouped to not grouped):

a) this useLayoutEffect is actually triggered by a dirty deps change (so we almost work), but because of "reasons related to virtualization", the measurement isn't correct, and we need to try again, or

b) this useLayoutEffect just isn't triggered at all when column is hidden/grouped, but the 200ms from the original/only invocation happens to catch it.

I'm thinking surely it's not b), because 200ms is so small...

Can you confirm a) vs. b)?

Fwiw my musing is that, because of virtualization, react-virtuoso (or GridTable) is being "smart" and not even causing our cell to get re-rendered?...

@blambillotte do you understand how/why this fix works?

Copy link
Contributor

@blambillotte blambillotte Oct 22, 2024

Choose a reason for hiding this comment

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

Interesting 🤔 I wonder if the check on line 40 is allowing the similar code (with the same setTimeout hack) on line 41 to run or not - I sort of assume the added time has no real impact vs just moving out of the sync call stack due to the setTimeout.
I can pull this down and poke a bit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stephenh this bug it's "hard" to reproduce, I think option b is the closest to what I've seen, but when it happens it is consistent, when trying to debug these it looked like 200ms was just enough for the onHeightChange to read the real final height and scroll states of the refs. I'll try to add a test that reproduces this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Really appreciate the storybook!

Maybe update this in-source comment to just include "See the InVirtualizedTable storybook for reproducing this behavior", so maintainers know exactly where to go to futz with this line/setTimeout.

@0ces 0ces merged commit 4ef1241 into main Oct 25, 2024
6 checks passed
@0ces 0ces deleted the SC-59775/fix-nested-select-height-after-long-render branch October 25, 2024 16:51
homebound-team-bot pushed a commit that referenced this pull request Oct 25, 2024
## [2.369.7](v2.369.6...v2.369.7) (2024-10-25)

### Bug Fixes

* SC-59775 fix nested select height after long render ([#1084](#1084)) ([4ef1241](4ef1241))
@homebound-team-bot
Copy link

🎉 This PR is included in version 2.369.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants