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

Provide nodeRef to Transition to fix StrictMode warning #3865

Merged
merged 20 commits into from
Jan 5, 2023

Conversation

LFDanLu
Copy link
Member

@LFDanLu LFDanLu commented Dec 20, 2022

Closes

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

Note: test off the branch locally for strictmode.

Turn on StrictMode via the checkbox in the storybook top toolbar and test stories that have Popovers/Modals/Trays/ActionBar/any type of overlay. There shouldn't be a strict mode console warning about findDOMNode. Note that there will be a different crash in FocusScope that is fixed by #3878

Running the strict mode tests will yield a mixed bag of passes/fails due to other strict mode bugs. #3878 fixes many of the FocusScope related issues

🧢 Your Project:

RSP

return (
<>
<div ref={wrapperRef}>
Copy link
Member Author

Choose a reason for hiding this comment

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

We could instead attach the nodeRef to the Underlay, however it doesn't exist in the isNonModal case with popover. Adding a wrapping div should be safe because Underlay and the overlay (Popover, Tray, Modal) all use position: fixed or position: absolute

@LFDanLu LFDanLu changed the title Strict mode fixes (WIP) Provide nodeRef to Transition to fix StrictMode warning Dec 20, 2022
@LFDanLu
Copy link
Member Author

LFDanLu commented Dec 20, 2022

@reidbarber the rebase got a bit hairy, seems to have blown away some of your commits. I think I reconstructed the changes you had made, but lemme know if anything was missing

@LFDanLu LFDanLu changed the title (WIP) Provide nodeRef to Transition to fix StrictMode warning Provide nodeRef to Transition to fix StrictMode warning Dec 20, 2022
Base automatically changed from strict_mode_per_story to main December 20, 2022 22:23
mischnic and others added 15 commits December 20, 2022 14:39
got rid of clone children in tooltip also since it would break if wrapper existed around the tooltip component
needed to provide an actual DOM ref to OpenTransition nodeRef
technically we could attach it to any DOM node in the Modal/Tray/Popover since we dont have a transition on enter, but for correctness with reflow/.scrollTop we want it as the wrapping element
For some reason, Ref doesnt break TS strict linter but RefObject does...
Copy link
Member

@ktabors ktabors left a comment

Choose a reason for hiding this comment

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

Code looks good. Haven't tested it yet.

@@ -78,8 +81,9 @@ const PopoverWrapper = forwardRef((props: PopoverWrapperProps, ref: RefObject<HT
maxHeight: null
}, state);

// Attach Transition's nodeRef to outer most wrapper for node.reflow: https://github.com/reactjs/react-transition-group/blob/c89f807067b32eea6f68fd6c622190d88ced82e2/src/Transition.js#L231
Copy link
Member

Choose a reason for hiding this comment

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

Why did you add the comment here and not to Modal.tsx or Tray.txs?

Copy link
Member Author

Choose a reason for hiding this comment

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

No particular reason, I can definitely add that to those components as well

import underlayStyles from '@adobe/spectrum-css-temp/components/underlay/vars.css';

interface UnderlayProps {
isOpen?: boolean,
isTransparent?: boolean
}

export function Underlay({isOpen, isTransparent}: UnderlayProps) {
function Underlay({isOpen, isTransparent}: UnderlayProps, ref: Ref<HTMLDivElement>) {
Copy link
Member

Choose a reason for hiding this comment

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

do we still need the ref here? i am not quite seeing where it coming from or being used

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, forgot to remove that

Copy link
Member

@reidbarber reidbarber left a comment

Choose a reason for hiding this comment

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

LGTM

@LFDanLu LFDanLu merged commit 9283b27 into main Jan 5, 2023
@LFDanLu LFDanLu deleted the strict-mode-fixes branch January 5, 2023 23:32
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.

5 participants