Reproduce github/primer#4027 - #5207
Closed
siddharthkp wants to merge 7 commits into
Closed
Conversation
|
siddharthkp
temporarily deployed
to
github-pages
November 1, 2024 10:52 — with
GitHub Actions
Inactive
Contributor
size-limit report 📦
|
siddharthkp
temporarily deployed
to
github-pages
November 1, 2024 11:02 — with
GitHub Actions
Inactive
siddharthkp
temporarily deployed
to
github-pages
November 1, 2024 11:27 — with
GitHub Actions
Inactive
refs do not trigger effect to rerun
Contributor
|
👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks! |
siddharthkp
temporarily deployed
to
github-pages
November 1, 2024 12:04 — with
GitHub Actions
Inactive
siddharthkp
commented
Nov 1, 2024
siddharthkp
temporarily deployed
to
github-pages
November 1, 2024 12:35 — with
GitHub Actions
Inactive
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Part 1: SelectPanel:
Video description:
reposition.mov
Not all that glitters...
Caveat: While the first part of the previous video looks like it's working perfectly, the panel only adjusts it's position once. So, if the length of the list changes again, for example while filtering, now the panel hangs awkwardly away from the anchor button.
far-away.mov
Part 2: AnchoredOverlay / useAnchoredPosition
This repositioning behavior comes from the underlying useAnchoredPosition hook and can be reproduced there as well:
The current behavior is implemented in AnchoredOverlay, but we may not want to change it for all AnchoredOverlays!
Part 3: When does an anchored overlay re-position itself?
This is the block of code that is of interest. to us:
https://github.com/primer/react/blob/main/packages/react/src/hooks/useAnchoredPosition.ts#L34-L48
So the position is re-calculate when
updatePositionchanges, that is when one offloatingElementRef,anchorElementRefordepdencieschanges.a. As the first 2 dependencies are refs, they only change once when they are filled and not after that.
b. The dependencies list from AnchoredOverlay has
overlayRef.currentwhich changes twice, once when the ref is filled and again when the overlay is closedWhen the SelectPanel is opened near the bottom of the screen (like in left half of the video), it causes the height of the page to grow, triggering the resize observer.
In the right half of the video, SelectPanel is inside a dialog and there is no increase in page height and hence resize observer is not triggered. (The same would happen without a dialog as well if the page has overflow hidden, which is the case in memex)
Part 4: Potential fix
One potential fix is to add another resize observer that watches for changes in size of the floating element:
useResizeObserver(updatePosition) // default target element is document + useResizeObserver(updatePosition, floatingElementRef)This does solve the solve the initial issue of the panel going out of screen, but trades it for a worse issue of constantly switching position when the size of the item changes 🤔
constant-switching.mov
A more complete fix is a more involved.
Notes from conversation with Maxime:
WIP PR: #5208
Related: Until now, there was no way to change anchorSide for select panel, there is however 4 instances that attempt it: 1 in dotcom and 3 in internal-statuspage