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

[crud] Basic implementation #31523

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

[crud] Basic implementation #31523

wants to merge 1 commit into from

Conversation

poteto
Copy link
Member

@poteto poteto commented Nov 12, 2024

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.

Copy link

vercel bot commented Nov 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 13, 2024 8:20pm

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Nov 12, 2024
@react-sizebot
Copy link

react-sizebot commented Nov 12, 2024

Comparing: 380f5d6...40630e4

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB = 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js +0.04% 506.73 kB 506.93 kB +0.15% 90.61 kB 90.75 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.04% 511.67 kB 511.86 kB +0.13% 91.31 kB 91.43 kB
facebook-www/ReactDOM-prod.classic.js +0.82% 588.71 kB 593.52 kB +0.55% 104.18 kB 104.75 kB
facebook-www/ReactDOM-prod.modern.js +0.83% 578.98 kB 583.78 kB +0.59% 102.59 kB 103.19 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
facebook-www/ReactART-dev.modern.js +1.68% 632.06 kB 642.69 kB +1.20% 101.11 kB 102.32 kB
facebook-www/ReactART-dev.classic.js +1.66% 641.94 kB 652.57 kB +1.21% 103.06 kB 104.31 kB
facebook-www/ReactReconciler-dev.modern.js +1.48% 717.46 kB 728.09 kB +0.94% 114.06 kB 115.14 kB
facebook-www/ReactReconciler-dev.classic.js +1.46% 726.97 kB 737.61 kB +0.97% 115.86 kB 116.98 kB
facebook-www/ReactART-prod.modern.js +1.36% 352.13 kB 356.94 kB +0.93% 59.61 kB 60.17 kB
oss-experimental/react/cjs/react.production.js +1.33% 18.07 kB 18.31 kB +1.09% 4.70 kB 4.75 kB
facebook-www/ReactART-prod.classic.js +1.33% 361.86 kB 366.66 kB +0.80% 61.18 kB 61.67 kB
facebook-react-native/react/cjs/React-prod.js +1.29% 18.74 kB 18.98 kB +1.07% 4.86 kB 4.91 kB
facebook-react-native/react/cjs/React-profiling.js +1.26% 19.17 kB 19.41 kB +1.03% 4.94 kB 4.99 kB
facebook-www/ReactReconciler-prod.modern.js +1.19% 444.04 kB 449.33 kB +0.82% 72.08 kB 72.67 kB
facebook-www/React-prod.modern.js +1.19% 20.34 kB 20.58 kB +1.04% 5.20 kB 5.25 kB
facebook-www/React-prod.classic.js +1.19% 20.34 kB 20.58 kB +1.04% 5.20 kB 5.25 kB
facebook-www/ReactReconciler-prod.classic.js +1.16% 454.36 kB 459.65 kB +0.79% 73.61 kB 74.20 kB
facebook-www/React-profiling.modern.js +1.16% 20.77 kB 21.01 kB +1.02% 5.28 kB 5.33 kB
facebook-www/React-profiling.classic.js +1.16% 20.77 kB 21.01 kB +1.02% 5.28 kB 5.33 kB
facebook-www/ReactDOM-dev.modern.js +1.02% 1,050.62 kB 1,061.29 kB +0.70% 176.18 kB 177.41 kB
facebook-www/ReactDOM-dev.classic.js +1.01% 1,060.07 kB 1,070.75 kB +0.71% 177.94 kB 179.20 kB
facebook-www/ReactDOMTesting-dev.modern.js +1.00% 1,067.52 kB 1,078.20 kB +0.70% 180.06 kB 181.32 kB
facebook-www/ReactDOMTesting-dev.classic.js +0.99% 1,076.97 kB 1,087.65 kB +0.69% 181.85 kB 183.10 kB
facebook-www/ReactDOM-prod.modern.js +0.83% 578.98 kB 583.78 kB +0.59% 102.59 kB 103.19 kB
facebook-www/ReactDOM-prod.classic.js +0.82% 588.71 kB 593.52 kB +0.55% 104.18 kB 104.75 kB
facebook-www/ReactDOMTesting-prod.modern.js +0.81% 593.70 kB 598.50 kB +0.56% 106.29 kB 106.89 kB
facebook-www/ReactDOMTesting-prod.classic.js +0.80% 603.43 kB 608.24 kB +0.51% 107.87 kB 108.42 kB
facebook-www/ReactDOM-profiling.modern.js +0.79% 606.09 kB 610.86 kB +0.55% 106.44 kB 107.02 kB
facebook-www/ReactDOM-profiling.classic.js +0.77% 615.87 kB 620.65 kB +0.53% 108.08 kB 108.66 kB
oss-experimental/react/cjs/react.development.js +0.65% 45.59 kB 45.88 kB +0.46% 10.42 kB 10.47 kB
facebook-react-native/react/cjs/React-dev.js +0.47% 62.84 kB 63.13 kB +0.36% 14.07 kB 14.12 kB
facebook-www/React-dev.modern.js +0.44% 67.57 kB 67.87 kB +0.34% 14.93 kB 14.98 kB
facebook-www/React-dev.classic.js +0.44% 67.58 kB 67.87 kB +0.34% 14.93 kB 14.98 kB
test_utils/ReactAllWarnings.js +0.43% 62.90 kB 63.17 kB +0.43% 15.67 kB 15.74 kB
oss-stable-rc/react-test-renderer/cjs/react-test-renderer.development.js +0.43% 547.45 kB 549.81 kB +0.22% 89.54 kB 89.74 kB
oss-stable-semver/react-test-renderer/cjs/react-test-renderer.development.js +0.43% 547.45 kB 549.81 kB +0.22% 89.54 kB 89.74 kB
oss-experimental/react-test-renderer/cjs/react-test-renderer.development.js +0.43% 547.48 kB 549.83 kB +0.22% 89.55 kB 89.75 kB
oss-stable/react-test-renderer/cjs/react-test-renderer.development.js +0.43% 547.51 kB 549.87 kB +0.22% 89.56 kB 89.76 kB
oss-stable-rc/react-art/cjs/react-art.development.js +0.43% 551.27 kB 553.63 kB +0.26% 89.25 kB 89.48 kB
oss-stable-semver/react-art/cjs/react-art.development.js +0.43% 551.27 kB 553.63 kB +0.26% 89.25 kB 89.48 kB
oss-stable/react-art/cjs/react-art.development.js +0.43% 551.33 kB 553.69 kB +0.26% 89.28 kB 89.51 kB
oss-experimental/react-art/cjs/react-art.development.js +0.41% 568.99 kB 571.35 kB +0.33% 92.04 kB 92.35 kB
facebook-www/ReactTestRenderer-dev.modern.js +0.41% 571.83 kB 574.19 kB +0.27% 93.59 kB 93.85 kB
facebook-www/ReactTestRenderer-dev.classic.js +0.41% 571.83 kB 574.19 kB +0.27% 93.59 kB 93.85 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-dev.js +0.41% 580.43 kB 582.79 kB +0.31% 94.56 kB 94.85 kB
oss-stable-rc/react-reconciler/cjs/react-reconciler.development.js +0.37% 634.18 kB 636.55 kB +0.16% 101.84 kB 102.00 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.development.js +0.37% 634.18 kB 636.55 kB +0.16% 101.84 kB 102.00 kB
oss-stable/react-reconciler/cjs/react-reconciler.development.js +0.37% 634.20 kB 636.57 kB +0.16% 101.86 kB 102.02 kB
react-native/implementations/ReactFabric-dev.js +0.37% 632.92 kB 635.28 kB +0.24% 103.63 kB 103.87 kB
react-native/implementations/ReactNativeRenderer-dev.js +0.37% 642.66 kB 645.01 kB +0.25% 105.31 kB 105.57 kB
oss-experimental/react-reconciler/cjs/react-reconciler.development.js +0.36% 650.69 kB 653.05 kB +0.18% 104.46 kB 104.65 kB
react-native/implementations/ReactFabric-dev.fb.js +0.36% 653.54 kB 655.90 kB +0.26% 107.10 kB 107.38 kB
react-native/implementations/ReactNativeRenderer-dev.fb.js +0.36% 660.51 kB 662.87 kB +0.26% 108.47 kB 108.75 kB
oss-stable-rc/react-dom/cjs/react-dom-client.development.js +0.26% 936.42 kB 938.83 kB +0.31% 158.47 kB 158.95 kB
oss-stable-semver/react-dom/cjs/react-dom-client.development.js +0.26% 936.42 kB 938.83 kB +0.31% 158.47 kB 158.95 kB
oss-stable/react-dom/cjs/react-dom-client.development.js +0.26% 936.53 kB 938.94 kB +0.31% 158.49 kB 158.98 kB
oss-stable-rc/react-dom/cjs/react-dom-profiling.development.js +0.25% 952.86 kB 955.27 kB +0.30% 161.30 kB 161.78 kB
oss-stable-semver/react-dom/cjs/react-dom-profiling.development.js +0.25% 952.86 kB 955.27 kB +0.30% 161.30 kB 161.78 kB
oss-stable/react-dom/cjs/react-dom-profiling.development.js +0.25% 952.97 kB 955.38 kB +0.30% 161.33 kB 161.81 kB
oss-experimental/react-dom/cjs/react-dom-client.development.js +0.25% 953.78 kB 956.19 kB +0.29% 161.32 kB 161.78 kB
facebook-react-native/react-dom/cjs/ReactDOMClient-dev.js +0.25% 970.07 kB 972.48 kB +0.27% 163.94 kB 164.39 kB
oss-experimental/react-dom/cjs/react-dom-profiling.development.js +0.25% 970.22 kB 972.63 kB +0.29% 164.15 kB 164.62 kB
oss-experimental/react-dom/cjs/react-dom-unstable_testing.development.js +0.25% 970.72 kB 973.13 kB +0.28% 165.10 kB 165.56 kB
facebook-react-native/react-dom/cjs/ReactDOMProfiling-dev.js +0.24% 986.42 kB 988.83 kB +0.27% 166.76 kB 167.20 kB

Generated by 🚫 dangerJS against ec5b340

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.
@@ -146,19 +153,56 @@ export function commitHookEffectListMount(

// Mount
let destroy;
if (enableUseResourceEffectHook) {
if (effect.kind === ResourceEffectIdentityKind) {
effect.resource = effect.create();
Copy link
Contributor

Choose a reason for hiding this comment

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

We might need a __DEV__ branch similar to what we have in the SimpleEffectKind flow where we handle the stacks.
Something like

effect.resource = runWithFiberInDEV(
  finishedWork,
  callCreateInDEV,
  effect,
);

Similar for the update calls. I see for destroy you've added safelyCallDestroyWithResource to handle it.

Comment on lines +313 to +314
effect.next.resource = null;
effect.next.update = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably the resource and update should live on the effect's instance object as well since they are stateful and modified in the same way as the destroy function.

It still feels unsafe to reach into the next effect. They are always pushed together though.

For the sake of the experiment, how about at least providing an else branch here with an error

if (effect.next.kind === ResourceEffectUpdateKind) {
  resetInstance(effect.next)
} else {
  throw new Error('Found identify effect without an update effect. This is a bug in React.');
}

Also add this above when assigning resource on the next effect

inst: EffectInstance,
create: () => mixed,
createDeps: Array<mixed> | void | null,
destroy: ((resource: mixed) => void) | void,
Copy link
Contributor

Choose a reason for hiding this comment

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

Mentioned above in regards to reseting the instances, but moving pushing the destroy function onto the instance (where it lives for SimpleEffect), as well as resource, makes these effect types more consistent. Then if the create/update and createDeps/updateDeps are made more generic, we're back to monomorphic shapes in the effect list.

});
}).toErrorDev(
'useResourceEffect received a dependency array with no dependencies. ' +
'When specified, the dependency array must have at least one dependency.',
Copy link
Contributor

Choose a reason for hiding this comment

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

At this point they have to be specified, right? Should we update message and also throw an error if no argument is provided?

await act(() => {
ReactNoop.render(null);
});
assertLog(['destroy(2, Jack)']);
Copy link
Contributor

Choose a reason for hiding this comment

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

😢

});

// @gate enableUseResourceEffectHook
it('calls update on every render if no deps are specified', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh didn't realize we were supporting this case in my comment above. Should we require null to be more explicit, or would you rather follow the current useEffect pattern for now? If we are more explicit while introducing this, it will be easier to compile later.

});

// @gate enableUseResourceEffectHook
it('unmounts on deletion after skipped effect', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Check if this is relevant / clarify description

@@ -92,6 +92,7 @@ export const retryLaneExpirationMs = 5000;
export const syncLaneExpirationMs = 250;
export const transitionLaneExpirationMs = 5000;
export const useModernStrictMode = true;
export const enableUseResourceEffectHook = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

__VARIANT__ ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants