Improving API for unstable shouldUpdate and onUpdate#9
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 |
| let node = root | ||
| while (true) { | ||
| if (node.tag === ReactClassComponent && shouldUpdate(node)) { | ||
| const publicInfo = extractPublicInfoFiber(node); |
There was a problem hiding this comment.
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!
| const fileName = internalInstance._debugSource && | ||
| internalInstance._debugSource.fileName; | ||
| return { | ||
| ref: internalInstance._instance, |
There was a problem hiding this comment.
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.
|
|
||
| function extractPublicInfoFiber(internalInstance) { | ||
| const fileName = internalInstance.child && | ||
| internalInstance.child._debugSource && |
There was a problem hiding this comment.
Why are you reading filename from the child rather than from the component itself?
There was a problem hiding this comment.
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.
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?
|
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.
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: