Skip to content

Create FocusScope nodes top down and add them bottom up#3898

Merged
devongovett merged 2 commits into
focusscope_strict_mode_fixfrom
simplify-focusscope-strict
Jan 11, 2023
Merged

Create FocusScope nodes top down and add them bottom up#3898
devongovett merged 2 commits into
focusscope_strict_mode_fixfrom
simplify-focusscope-strict

Conversation

@devongovett
Copy link
Copy Markdown
Member

@devongovett devongovett commented Jan 9, 2023

Simplification of #3878.

It works by creating the tree nodes during render (top down), and passing them down via context. In a layout effect (bottom up), it adds itself to its parent and to the tree. If the parent is already in the tree, then we consider activeScope as the parent.

@devongovett devongovett force-pushed the simplify-focusscope-strict branch from b1792c2 to a309df4 Compare January 9, 2023 17:54
@devongovett devongovett mentioned this pull request Jan 9, 2023
5 tasks
@devongovett devongovett requested review from LFDanLu and snowystinger and removed request for LFDanLu January 9, 2023 17:55
Copy link
Copy Markdown
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

I'm not so sure this is equivalent, this fails one more strict mode test compared to the base branch
I can't easily tell which one, would need to compare junit XML entries or something

@devongovett
Copy link
Copy Markdown
Member Author

hmm? as far as I can tell all the tests pass. what are you seeing?

@snowystinger
Copy link
Copy Markdown
Member

Base PR has 639 failures in strictmode across all components. This PR has 640. yarn test-strict
So that's why I'm saying not sure what the actual difference is yet. Unfortunately I can't just diff the junit's. Maybe I can if run in band, I'll try that.

@snowystinger
Copy link
Copy Markdown
Member

runInBand actually fails worse, no summary for either base branch or this PR, so no junit.xml report. will need to find some other way of getting the summary of just the tests and not the extra info and in the same order

@devongovett
Copy link
Copy Markdown
Member Author

How is junit involved here? When I run yarn test-strict it outputs as normal. yarn test-strict focusscope passes also

@snowystinger
Copy link
Copy Markdown
Member

snowystinger commented Jan 10, 2023

junit is just the reporting, gets logged for every jest run. was just looking for an easy way to compare the test on this branch vs on the base. (to see why it's 640 failures instead of 639)
the issue is, the reporting is in a different order because jest runs in parallel and sometimes test suites run in a different order. so I was trying --runInBand to get the same run order, but that fails to complete, therefore no reporting

w/o runInBand though, I see this branch fails one more test than the base. I just haven't spent more time than the above steps to determine which one is the extra failing test on this branch

do you not see any failures when you run yarn strict-mode across everything?

@devongovett
Copy link
Copy Markdown
Member Author

Oh I see 649 failing.

I copied the test output to a file and ran this:

cat a.txt | grep '' | sort > a-sorted.txt
cat b.txt | grep '' | sort > b-sorted.txt
diff a-sort.txt b-sort.txt
405a406
>   ● Picker › closing › closes on blur

Haven't figured out why it fails.

Copy link
Copy Markdown
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

LGTM, did some extra testing around nodeToRestore and it seems to work as expected

@devongovett devongovett merged commit cb5eab2 into focusscope_strict_mode_fix Jan 11, 2023
@devongovett devongovett deleted the simplify-focusscope-strict branch January 11, 2023 17:10
LFDanLu added a commit that referenced this pull request Jan 11, 2023
* tentative change to fix FocusScope strict mode

* cleanup

* step back some optimization until we fix all issues

* properly assign new top level scope parent

fix case where deleting a row via actionbar didnt restore focus to the new first row.

* fix table crud case

* add optimizations to fit assumptions

* fix ButtonGroup strictmode test

* fixing focuscope test for strict mode

* making DialogTrigger tests not fail due to strict mode

since strict mode unmounts and rerenders the dialog, we will always run into the "unmounted while open" error in the tests if defaultOpen or isOpen is true. Since I think we cant distingush a true unmount case vs strict modes unmount case, I opted to suppress the warning in the test instead

* ensure activeScope is accurate

in strict mode, the layouteffect cleanup triggers even when the focusscope hasnt unmounted. This makes activeScope inaccurate and breaks the parentScope for future nested focusscopes (e.g. nested dialog trigger case)

* fixing tabs tests

* removing extraneous parentScope calculation

* more cleanup

* updating test for strict mode and non strict mode consistency

the previous expect was relying on the fact that ButtonGroup first measurement happened before we mock the widths and positions of the buttons + buttongroups. That doesnt work well in strict mode and didnt feel reflective of browser behavior so I removed that expect

* Create FocusScope nodes top down and add them bottom up (#3898)

Co-authored-by: Devon Govett <devongovett@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants