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

Added findDOMNode, as we move toward deprecating g #2646

Merged
merged 1 commit into from
Dec 22, 2014

Conversation

jimfb
Copy link
Contributor

@jimfb jimfb commented Dec 3, 2014

Added findDOMNode, as we move toward deprecating getDOMNode

@syranide
Copy link
Contributor

syranide commented Dec 3, 2014

I haven't followed any discussions, but this naming seems weird. find (vs get) seems like an implementation detail to me.

Nevermind me... or?

@jimfb
Copy link
Contributor Author

jimfb commented Dec 3, 2014

The bigger thing is that we're moving it off the component and into a static helper/utility function. That's the structural change, the name change is more of an "oh, while we're making the api change here, let's fix the name also, so users don't need to do two migrations"

I don't remember all the reasons we didn't like "get", but I think one of them might have been related to the fact that we may not have a 1-to-1 mapping from react components to dom nodes ([might be 1-to-0 today, might be extended to 1-to-n in future] - maybe I just made that up), and "get" has a connotation of being an instance method with a 1-to-1 mapping. Regardless, I know we were talking about "queryDOMNode" and "selectDOMNode", both of which were too easily confused with jquery selectors. Sema indicated we should go with "findDOMNode"

@zpao
Copy link
Member

zpao commented Dec 3, 2014

@syranide no, you didn't miss any explicit discussion. This is part of the decoupling that @sebmarkbage has been working on but some of the details haven't been well communicated. Specifically in this case, getDOMNode is already a thing mixed in only for DOM composite components and as we make the idea of components more generic, having this.getDOMNode available becomes riskier because the class might not be a DOM component class (eg it doesn't make any sense for a canvas rendered component to correlate to any DOM node). We can control it better at the top level instead of just having the engine throw undefined is not a function.

I'm not entirely happy with naming so we could probably bikeshed some more if you want. I'm personally leaning towards React.$() :trollface:

if (isDomElement(element)) {
return element;
}
invariant(false, 'Assert: NOT REACHED (keys: '+Object.keys(element)+')');
Copy link
Member

Choose a reason for hiding this comment

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

We'll want a better message here. Also, we need to use printf format (with only %s), not string concat. invariant(condition, 'some %s string %s', 1, 2)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better?

@jimfb jimfb force-pushed the getDOMNode-becomes-findDOMNode branch 3 times, most recently from e419094 to 414717c Compare December 4, 2014 01:33
return element;
}
invariant(false,
'Element appears to be neither ReactComponent nor DOMNode (keys: %s)',
Copy link
Member

Choose a reason for hiding this comment

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

nit: false on new line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@jimfb jimfb force-pushed the getDOMNode-becomes-findDOMNode branch from 414717c to 1d55163 Compare December 4, 2014 18:39
@jimfb jimfb force-pushed the getDOMNode-becomes-findDOMNode branch 2 times, most recently from fe77ef8 to 0308e03 Compare December 8, 2014 20:45
@sebmarkbage
Copy link
Collaborator

This should move into the browser folder since it's DOM specific.

return ReactMount.getNodeFromInstance(componentOrElement);
}
invariant(
!(componentOrElement.render != null && typeof(componentOrElement) === 'function'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you meant to check typeof componentOrElement.render === 'function', not the componentOrElement itself. Please add a unit test that covers this error message case.

@jimfb jimfb force-pushed the getDOMNode-becomes-findDOMNode branch 3 times, most recently from 903f056 to 0810b08 Compare December 18, 2014 21:39
@jimfb jimfb force-pushed the getDOMNode-becomes-findDOMNode branch from 0810b08 to 8bbc60c Compare December 18, 2014 21:44
@sebmarkbage
Copy link
Collaborator

👍

jimfb added a commit that referenced this pull request Dec 22, 2014
Added findDOMNode, as we move toward deprecating getDOMNode
@jimfb jimfb merged commit e072534 into facebook:master Dec 22, 2014
@jimfb jimfb deleted the getDOMNode-becomes-findDOMNode branch December 22, 2014 21:05
invariant(
!(componentOrElement.render != null && typeof(componentOrElement.render) === 'function'),
'Component contains `render` method but is not mounted in the DOM',
Object.keys(componentOrElement)
Copy link
Member

Choose a reason for hiding this comment

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

There is no %s so these won't be inserted anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excellent catch, thanks!

@jimfb
Copy link
Contributor Author

jimfb commented Jan 2, 2015

Updated diff: #2800

josephsavona pushed a commit that referenced this pull request May 15, 2024
Summary: Currently Forget bails on mutations to globals within any callback function. However, callbacks passed to useEffect should not bail and are not subject to the rules of react in the same way.

We allow this by instead of immediately raising errors when we see illegal writes, storing the error as part of the function. When the function is called, or passed to a position that could call it during rendering, we bail as before; but if it's passed to `useEffect`, we don't raise the errors.
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.

4 participants