-
Notifications
You must be signed in to change notification settings - Fork 47k
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
[crud] Basic implementation #31416
[crud] Basic implementation #31416
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
if (__DEV__) { | ||
if ((flags & HookInsertion) !== NoHookEffect) { | ||
setIsRunningInsertionEffect(true); | ||
} | ||
destroy = runWithFiberInDEV(finishedWork, callCreateInDEV, effect); | ||
if (effect.kind === SimpleEffectKind) { |
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.
Ditto here for the feature flag behavior
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.
this one is still needed because i unconditionally change the shape of the Effect type, so we do still need this check. i could probably console.error or something if the flag is disabled and the effect kind isn't the simple one
enableUseResourceEffectHook && | ||
effect.kind === ResourceEffectKind | ||
) { | ||
hookName = 'useResourceEffect'; |
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.
Ditto no failing test
effect.resource != null && | ||
(effect.create != null || | ||
// TODO(@poteto) this feels gross | ||
finishedWork.return == null) |
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.
This only works because in the tests the App
component is the root component, so there's no return
fiber to the parent. We need to find a better way to do this that works through multiple layers.
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.
I.e. this test fails:
it('unmounts on deletion after skipped effect', async () => {
function Wrapper(props) {
return <App {...props} />
}
function App({id, username}) {
const opts = useMemo(() => {
return {username};
}, [username]);
useResourceEffect(
() => {
const resource = new Resource(id, opts);
Scheduler.log(`create(${resource.id}, ${resource.opts.username})`);
return resource;
},
[id],
resource => {
resource.update(opts);
Scheduler.log(`update(${resource.id}, ${resource.opts.username})`);
},
[opts],
resource => {
resource.destroy();
Scheduler.log(`destroy(${resource.id}, ${resource.opts.username})`);
},
);
return <Text text={'Id: ' + id} />;
}
await act(async () => {
ReactNoop.render(<Wrapper id={0} username="Sathya" />, () =>
Scheduler.log('Sync effect'),
);
await waitFor(['Id: 0', 'Sync effect']);
expect(ReactNoop).toMatchRenderedOutput(<span prop="Id: 0" />);
});
assertLog(['create(0, Sathya)']);
await act(async () => {
ReactNoop.render(<Wrapper id={0} username="Lauren" />, () =>
Scheduler.log('Sync effect'),
);
await waitFor(['Id: 0', 'Sync effect']);
expect(ReactNoop).toMatchRenderedOutput(<span prop="Id: 0" />);
});
assertLog(['update(0, Lauren)']);
ReactNoop.render(null);
await waitForAll(['destroy(0, Lauren)']);
expect(ReactNoop).toMatchRenderedOutput(null);
});
) { | ||
const destroy_ = resource == null ? destroy : destroy.bind(null, resource); |
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.
What if you return null
as the resource?
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.
This PR introduces a new experimental hook `useResourceEffect`, which is something that we're doing some very early initial tests on. This may likely not pan out and will be removed or modified if so. Please do not rely on it as it will break.
Sapling messed up my PR, opening a new one |
This PR introduces a new experimental hook
useResourceEffect
, which is something that we're doing some very early initial tests on.This may likely not pan out and will be removed or modified if so. Please do not rely on it as it will break.
Stack created with Sapling. Best reviewed with ReviewStack.