fix(CodeSnippet): overflow indicators updated onResize #9605
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #8441
Codesnippet had a bug that did not update the "overflow indicator" (gradient) when window was resized. This PR addresses that bug.
Removed
debounce
callback in theresizeObserver
because I realized it wasn't actually running the callback after 200ms. I think this is a lodash bug but I couldn't find any helpful issues related to this bug.How I came to this conclusion
handleScroll()
handleScroll
was being useda. within a
useEffect
hookb. within
useResizeObserver
which has anonResize
callback that updates several states for multi & single line snippetsc. within
onScroll
for the single & multilinediv
shasLeftOverflow
hasRightOverflow
were being updated properly each timehandleScroll
was being calledconsole.log
within theonResize
conditional wherehandleScroll
was being called to see if we were even getting within that conditional when resizing.We were "getting there". Which then led me to realize that for some reason, the debounce callback wasn't working.
handleScroll
instead and tested resizing the window. This time the overflow indicator states were updated properly.onResize
, I figured it was ok.Testing / Reviewing
a. check that right overflow indicator displays initially
b. scroll slightly right and check that left and right indicators display
c. scroll all the way right, and right indicator should go away
d. now resize the window so that the codesnippet component becomes smaller. The resizing should update the overflow indicators.
You can test it against this video (recording of bug) and notice the overflow indicator working on window resize.
Screen.Recording.2021-08-25.at.11.27.05.AM.mov