-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Refactor fill component to avoid relying on componentWillUpdate and use React Hooks instead #15541
Conversation
…se React Hooks instead
Some more context at #3472 (comment) . I think the main idea is to force all fills to render again via I worry a bit that it might rely on very specific lifecycle timing (the before render behavior of |
@aduth do you know if there's a test covering this as it would help here. |
@youknowriad There was a test case added in the relevant commit, yes. In that case, we may be able to judge by this passing. |
Ok tests are failing which is good as it confirms the issue but the issue is I have no idea how to fix this right now. I'll probably rethink about it tomorrow. |
I give up on this one, I was not able to make the tests pass. I feel like I'm not far from finding a solution though. |
I think I found a fix for the reordering issue, let's see what the tests say. |
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.
It's complex stuff. I don't fully understand all changes applied but based on Travis reaction I'm happy with the proposal :)
I strongly recommend another pair of eyes on this PR before you proceed.
function FillComponent( { name, getSlot, children, registerFill, unregisterFill } ) { | ||
// Random state used to rerender the component if needed, ideally we don't need this | ||
const [ , updateRerenderState ] = useState( {} ); | ||
const rerender = () => updateRerenderState( {} ); |
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.
According to @gaearon
https://twitter.com/dan_abramov/status/1118301474876948480
you can do this:
const [, forceUpdate] = useReducer(x => x + 1, 0)
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.
yes, not sure which one is best. I guess it doesn't matter that much
@youknowriad just checking whether it was ever merged to master as I don't find it in the master that uses react-hooks. |
Yes, this was merged. you're maybe looking at the wrong master (your fork or something?) |
Oh sorry, i see it now. |
This RR might introduce a regression which isn't covered with tests: |
Per #15541 (comment), it is intended to be covered with tests, though if it is in-fact a regression, it would appear coverage could be improved. |
Refs #11360
I'm not familiar with the details of the slot/fill implementation especially the occurences thing so please make sure to test this extensively.
Testing instructions