-
Notifications
You must be signed in to change notification settings - Fork 19
Improving API for unstable shouldUpdate and onUpdate #9
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
base: master
Are you sure you want to change the base?
Conversation
|
Will this allow inspecting the ref to see what context names it's subscribed to? If not, that would be useful information to expose as well. |
|
@wmertens is that information available in |
|
I am not sure, this is the approach I took before: https://github.com/gaearon/react-deep-force-update/pull/4/files#diff-1fdf421c05c1140f6d71444ea2b27638R25 Basically, if the contextName is a function on the class's |
|
@wmertens, I see from your code that you were using |
src/index.js
Outdated
| let node = root | ||
| while (true) { | ||
| if (node.tag === ReactClassComponent && shouldUpdate(node)) { | ||
| const publicInfo = extractPublicInfoFiber(node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems unfortunate to call it if it's not used. I guess this is the point where I ask you to change it back to check the function existence inline (and lazily calculate this if either function exists). Sorry!
src/index.js
Outdated
| const fileName = internalInstance._debugSource && | ||
| internalInstance._debugSource.fileName; | ||
| return { | ||
| ref: internalInstance._instance, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename this field to publicInstance. The instance doesn't really have a ref and it can be a bit confusing to overload this term.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(y)
src/index.js
Outdated
|
|
||
| function extractPublicInfoFiber(internalInstance) { | ||
| const fileName = internalInstance.child && | ||
| internalInstance.child._debugSource && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you reading filename from the child rather than from the component itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I could see while playing around in Power Editor, if I'm looking for an instance of component Foo, defined in foo.js, It will be Foo's children who will have _debugSource.fileName === 'foo.js'. I couldn't test this with stack-based React since it seems it's not that easy to turn that on for Facebook code anymore, but for Fiber, it's working really well in practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, I just don't understand why. This doesn't really make sense to me: a child is the child component, not the current component. Maybe you could give an example of component I could look at where children have filenames but parents don't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Sounds good, will update soon. |
3de9de3 to
d14d98f
Compare
|
This removes support for shouldUpdate and onUpdate for stack-based React. We should make sure to address #10. |
|
@bfiss you should add test on Fiber if possible |
46ef848 to
e2a60b3
Compare
|
Talked with @gaearon and we decided to upgrade React to 16. This will automatically get the tests on Fiber. |
|
There's a new warning, but I guess it should be okay to ignore:
|
|
Thank you so much for your work 🙏 |
gaearon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to avoid reading the tag field. This means both changing the shouldUpdate callback to not take it, and changing the class check to something like
const hasInstance =
node.stateNode !== null &&
typeof node.type === 'function';(I already upstreamed this change on www)

Addressing issue #8 . Thanks @gaearon for the reviews.
This only exposes: