-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
[react-cache] Remove cache
as argument to read
#13865
Conversation
LogError: { FetchError: invalid json response body at http://react.zpao.com/builds/master/_commits/80a0c05ce3e0e1babe5c8fc97ef24fd67cb4e735/results.json reason: Unexpected token < in JSON at position 0
at /home/circleci/project/node_modules/node-fetch/lib/body.js:48:31
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
name: 'FetchError',
message: 'invalid json response body at http://react.zpao.com/builds/master/_commits/80a0c05ce3e0e1babe5c8fc97ef24fd67cb4e735/results.json reason: Unexpected token < in JSON at position 0',
type: 'invalid-json' }
Generated by 🚫 dangerJS |
f4d7486
to
71f1677
Compare
ReactFeatureFlags = require('shared/ReactFeatureFlags'); | ||
ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false; | ||
ReactFeatureFlags.replayFailedUnitOfWorkWithInvokeGuardedCallback = false; | ||
ReactFeatureFlags.enableSuspense = true; |
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.
IIRC, enableSuspense
has been removed in #13799 ?
throw new Error( | ||
'react-cache: read and preload may only be called from within a ' + | ||
"component's render. They are not supported in event handlers or " + | ||
'life-cycles.', |
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.
“lifecycle methods”?
|
||
function readContext(Context, observedBits) { | ||
const dispatcher = | ||
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner |
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 hoist CurrentOwner? No need to access it many times.
<Suspense> | ||
<AsyncText ms={100} text={1} /> | ||
<AsyncText ms={100} text={2} /> | ||
<AsyncText ms={100} text={3} /> |
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.
Should we use or add a PureComponent of AsyncText case like :
<AsyncText ms={100} text={2} />
<AsyncText ms={100} text={3} />
<AsyncText ms={100} text={1} />
here? IMO, we need a case which test the cache read and common reconciliation together.
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 test does read from the cache? And idk what you mean by "common reconciliation"
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.
Sorry. I mean, this just test the function component(the AsyncText
) but in real world, we have class component which can be PureComponent
or normal Component
, so in the common reconciliation and update, they will go to different switch cases or codes, I think maybe it also should be tested with the cache read processing. @acdlite
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.
Dan's comments.
resolvedRecord.status = Resolved; | ||
resolvedRecord.suspender = null; | ||
resolvedRecord.value = value; | ||
if (newResult.status === Pending) { |
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 is this status
check guarding against?
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.
Guards against something resolving multiple times. Promises don't do that but a thenable might. Thanks for pointing this out, though, because now I realize I didn't write a test for it.
Updated is API is `Resource.read(key)` instead of `Resource.read(cache, key)`. The cache is read from context using `readContext`. This also removes cache invalidation entirely (other than the default LRU mechanism), as well as the ability to have multiple caches. We'll add it back once `Context.write` lands and we can implement it the right way. Since there's now only a single cache (the global one), we don't actually need to use context yet, but I've added a dummy context anyway so the user gets an error if they attempt to read outside the render phase.
Some breaking changes in the unstable APIs of Suspense: * No more need to use `enableSuspense` * flag in https://github.com/facebook/react/blob/master/packages/shared/ReactFeatureFlags.js#L48 * To generate custom build, use: `yarn build dom-client,core,react-cache,scheduler --type=NODE` * facebook/react@8af6728#diff-e7efbec821bc95957204c2fcbd251e74 * `<Placeholder delayMs />` renamed to `<Suspense maxDuration />` * facebook/react@8af6728 * facebook/react@d75c69e * react-cache * Add "unstable_" prefix - `createResource` becomes `unstable_createResource` * facebook/react@915e4ea * Remove `cache` as argument to `read` * facebook/react#13865
Some breaking changes in the unstable APIs of Suspense: * No more need to use `enableSuspense` * flag in https://github.com/facebook/react/blob/master/packages/shared/ReactFeatureFlags.js#L48 * To generate custom build, use: `yarn build dom-client,core,react-cache,scheduler --type=NODE` * facebook/react@8af6728#diff-e7efbec821bc95957204c2fcbd251e74 * `<Placeholder delayMs />` renamed to `<Suspense maxDuration />` * facebook/react@8af6728 * facebook/react@d75c69e * react-cache * Add "unstable_" prefix - `createResource` becomes `unstable_createResource` * facebook/react@915e4ea * Remove `cache` as argument to `read` * facebook/react#13865
* [react-cache] Remove `cache` as argument to `read` Updated is API is `Resource.read(key)` instead of `Resource.read(cache, key)`. The cache is read from context using `readContext`. This also removes cache invalidation entirely (other than the default LRU mechanism), as well as the ability to have multiple caches. We'll add it back once `Context.write` lands and we can implement it the right way. Since there's now only a single cache (the global one), we don't actually need to use context yet, but I've added a dummy context anyway so the user gets an error if they attempt to read outside the render phase. * nits * Add test for thenables that resolve multiple times
Updated is API is
Resource.read(key)
instead ofResource.read(cache, key)
.The cache is read from context using
readContext
.This also removes cache invalidation entirely (other than the default LRU mechanism), as well as the ability to have multiple caches. We'll add it back once
Context.write
(some version of #13293) lands and we can implement it the right way.Since there's now only a single cache (the global one), we don't actually need to use context yet, but I've added a dummy context anyway so the user gets an error if they attempt to read outside the render phase.