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

feat!: add StrictMode support #5687

Merged
merged 3 commits into from Mar 8, 2021
Merged

feat!: add StrictMode support #5687

merged 3 commits into from Mar 8, 2021

Conversation

kyletsang
Copy link
Member

An attempt at fixing strict mode issues for transitions, carousel and overlay trigger.

Fixes #5519
Fixes #5075

@kyletsang kyletsang requested a review from jquense March 1, 2021 22:15
@kyletsang kyletsang linked an issue Mar 1, 2021 that may be closed by this pull request
@kyletsang kyletsang added this to In Progress in v5 support via automation Mar 1, 2021
};

// Normalizes Transition callbacks when nodeRef is used.
const TransitionWrapper = React.forwardRef<
Copy link
Member

Choose a reason for hiding this comment

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

I can never remember what RTG is doing now...do we need this wrapper? If it's in v5 can we just break the API and require node ref compatible components?

Copy link
Member Author

Choose a reason for hiding this comment

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

RTG has this quirk where the node is excluded in the callback signature when using nodeRef.

ie. (node, isAppearing) => ... becomes (isAppearing) => ...

This wrapper abstracts all that so callers don't have to worry about it (like they can just use it like it was without using nodeRef). I kinda figured this would be a cleaner approach.

Copy link
Member

Choose a reason for hiding this comment

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

ah, that seems like a bad API choice i probably ok'd oops

@@ -229,19 +230,20 @@ const Collapse = React.forwardRef(
onEntered={handleEntered}
onExit={handleExit}
onExiting={handleExiting}
childRef={(children as any).ref}
Copy link
Member

Choose a reason for hiding this comment

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

this will always be falsey, children, if it's an element would have ref on children.props not on the element itself

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm children.ref is actually defined when I was testing this. I've tried children.props.ref but I get a warning:

Warning: div: ref is not a prop. Trying to access it will result in undefined being returned. If you need to access the same value within the child component, you should pass it as a different prop.

Copy link
Member Author

Choose a reason for hiding this comment

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

tbh, children.ref did seem kinda hacky (esp. with the casting). I'm not 100% sure on what the correct approach is :P

Copy link
Member

Choose a reason for hiding this comment

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

o hmm i must have it backwards, been doing this for too long. I'm suprised the types don't correctly cover this tho

Copy link
Member Author

Choose a reason for hiding this comment

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

I found this on the react github project that seems to confirm the children.ref usage:

facebook/react#8873 (comment)

ref={ref}
addEndListener={transitionEndListener}
{...props}
onEnter={handleEnter}
childRef={(children as any).ref}
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@@ -186,6 +181,10 @@ function OverlayTrigger({
...props
}: OverlayTriggerProps) {
const triggerNodeRef = useRef(null);
const mergedRef = useMergedRefs<unknown>(
triggerNodeRef,
(children as any).ref,
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@kyletsang kyletsang linked an issue Mar 3, 2021 that may be closed by this pull request
@kyletsang kyletsang merged commit 237d9f8 into bs5-dev Mar 8, 2021
v5 support automation moved this from In Progress to Done Mar 8, 2021
@kyletsang kyletsang deleted the feat/strict-mode branch March 8, 2021 17:38
@FunctionDJ
Copy link
Contributor

This will only be in v5, not v4, correct?

@kyletsang
Copy link
Member Author

This will only be in v5, not v4, correct?

Correct

@jgomez-nydig
Copy link

This will only be in v5, not v4, correct?

Correct

Looking at the tags I see 1.5.2 and 2.x, what are v5 and v4?

@kyletsang
Copy link
Member Author

This will only be in v5, not v4, correct?

Correct

Looking at the tags I see 1.5.2 and 2.x, what are v5 and v4?

V4 and v5 corresponds to the bootstrap versions, so in terms of react bootstrap this would be 1.x and 2.x respectively.

@augustjanse
Copy link

I was under the impression that react-bootstrap@next would fix these warnings, but I'm still getting them with OverlayTrigger and Tooltip. I pushed an example here. Am I mistaken?

@kyletsang
Copy link
Member Author

@augustjanse, try passing a function as a child to OverlayTrigger.

See: https://react-bootstrap.netlify.app/components/overlays/#customizing-trigger-behavior

@augustjanse
Copy link

Oh! As you might have guessed, I didn't realize that the other way of doing it would still trigger the warnings. This worked fine, thanks!

adamayres added a commit to lithiumtech/react-bootstrap that referenced this pull request Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v5 support
  
Done
Development

Successfully merging this pull request may close these issues.

OverlayTrigger - findDOMNode is deprecated in StrictMode Warning: findDOMNode is deprecated in StrictMode.
5 participants