-
Notifications
You must be signed in to change notification settings - Fork 38
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
New and improved useOverflow
algorithm
#2154
base: r/overflow-container-without-new-algorithm
Are you sure you want to change the base?
New and improved useOverflow
algorithm
#2154
Conversation
…verflow-new-algorithm
d5fec07
to
d964096
Compare
…verflow-new-algorithm
…verflow-new-algorithm
…verflow-new-algorithm
…verflow-new-algorithm
…verflow-new-algorithm
…verflow-new-algorithm
…verflow-new-algorithm
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.
Before I review this, could you list out somewhere (in order) all PRs in the stack? It's a bit difficult to tell at a glance which PR goes where. I'm also not sure of the current status of #2152 (it's been open for 2 months).
Also it would be good to start merging some of the earlier PRs in the stack, unless there is a strong reason to keep them around. Long-lived branches can be difficult to keep up-to-date.
Sounds good, I mentioned it in #2120 (comment).
There's one unresolved comment that I had already replied to. If it resolves your comment, you can mark it as resolved. There's nothing else that I plan to add to that PR, unless we realize we need to change something in this PR when reviewing other PRs in the stack that merge into this one.
Sounds good, will merge those PRs soon if it seems like there will likely be no more changes needed in them. |
…verflow-new-algorithm
…verflow-new-algorithm
Changes
Pulled out of #2120 as PR 4 in the PR stack (PR stack order).
As mentioned in #2112 (comment), I believe the flickering is because of an infinite loop:
I think this is because our
useOverflow
hook makes the assumption that all items are around the same size and thus we can take an average:iTwinUI/packages/itwinui-react/src/utils/hooks/useOverflow.tsx
Line 79 in 4f431e5
While this may work for cases like the TablePaginator, it doesn't seem to work for the ComboBox case where tags could have different widths.
Thus,
useOverflow
should be refactored to use real sizes.Logic of new algorithm for
useOverflow
:visibleCount
. e.g.[0, 32]
(32 is an arbitrary choice).i.e. the max guess should always be
≥
the correctvisibleCount
.visibleCount
to themaxGuess
.guessVisibleCount()
(keep re-rendering but not painting):visibleCount
.Why this works:
log(n)
.Others:
useOverflow
removesdisabled
argument since we can just conditionally renderOverflowContainer
. (NewOverflowContainer
wrapper arounduseOverflow
#2152 (comment))useOverflow
returns the same values that is used to return before this PR. I didn't re-implement the WIP logic whereuseOverflow
returned one more than the total number of items when all items are visible. (NewOverflowContainer
wrapper arounduseOverflow
#2152 (comment))Testing
scrollWidth
andoffsetWidth
was no longer reasonable with the new algorithm implementation. Equivalent e2e already added in e2e tests foruseOverflow
logic #2151 from the PR chain.overflowStart
is correct:overflowStart
with a playground from3.13.1
with the same code.When testing, I realized that in addition to fixing this bug, this PR also might improve performance. Specifically, the old algorithm made infinite changes in the DOM even when there is no flickering visually. But the new algorithm doesn't make these continuous DOM updates.
Code
Result
Before:
Halfway through the video, I increased the throttling percentage.
Enregistrement.de.l.ecran.2024-10-01.a.11.50.13.reduced.mov
After:
Enregistrement.de.l.ecran.2024-10-01.a.11.09.56.mov
Docs