Skip to content
Branch: master
Find file History
sebmarkbage Add withSuspenseConfig API (#15593)
* Add suspendIfNeeded API and a global scope to track it

Adds a "current" suspense config that gets applied to all updates scheduled
during the current scope.

I suspect we might want to add other types of configurations to the "batch"
so I called it the "batch config".

This works across renderers/roots but they won't actually necessarily go
into the same batch.

* Add the suspenseConfig to all updates created during this scope

* Compute expiration time based on the timeout of the suspense config

* Track if there was a processed suspenseConfig this render pass

We'll use this info to suspend a commit for longer when necessary.

* Mark suspended states that should be avoided as a separate flag

This lets us track which renders we want to suspend for a short time vs
a longer time if possible.

* Suspend until the full expiration time if something asked to suspend

* Reenable an old test that we can now repro again

* Suspend the commit even if it is complete if there is a minimum delay

This can be used to implement spinners that don't flicker if the data
and rendering is really fast.

* Default timeoutMs to low pri expiration if not provided

This is a required argument in the type signature but people may not
supply it and this is a user facing object.

* Rename to withSuspenseConfig and drop the default config

This allow opting out of suspending in some nested scope.

A lot of time when you use this function you'll use it with high level
helpers. Those helpers often want to accept some additional configuration
for suspense and if it should suspend at all. The easiest way is to just
have the api accept null or a suspense config and pass it through. However,
then you have to remember that calling suspendIfNeeded has a default.

It gets simpler by just saying tat you can pass the config. You can have
your own default in user space.

* Track the largest suspense config expiration separately

This ensures that if we've scheduled lower pri work that doesn't have a
suspenseConfig, we don't consider its expiration as the timeout.

* Add basic tests for functionality using each update mechanism

* Fix issue when newly created avoided boundary doesn't suspend with delay

* Add test for loading indicator with minLoadingDurationMs option
Latest commit 9c6de71 May 16, 2019
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
__tests__ Remove <ConcurrentMode /> (#15532) May 13, 2019
forks Fork ReactSharedInternals for UMD builds (#15617) May 10, 2019
React.js Add withSuspenseConfig API (#15593) May 16, 2019
ReactBaseClasses.js Drop the year from Facebook copyright headers and the LICENSE file. (#… Sep 7, 2018
ReactBatchConfig.js Add withSuspenseConfig API (#15593) May 16, 2019
ReactChildren.js Drop the year from Facebook copyright headers and the LICENSE file. (#… Sep 7, 2018
ReactContext.js Use unique thread ID for each partial render to access Context (#14182) Nov 9, 2018
ReactCreateEventComponent.js Add React.unstable_createEventComponent (#15580) May 7, 2019
ReactCreateRef.js Drop the year from Facebook copyright headers and the LICENSE file. (#… Sep 7, 2018
ReactCurrentBatchConfig.js Add withSuspenseConfig API (#15593) May 16, 2019
ReactCurrentDispatcher.js Phased dispatcher (#14701) Jan 30, 2019
ReactCurrentOwner.js Separate current owner and dispatcher (#14548) Jan 8, 2019
ReactDebugCurrentFrame.js Drop the year from Facebook copyright headers and the LICENSE file. (#… Sep 7, 2018
ReactElement.js Provide new jsx transform target for reactjs/rfcs#107 (#15141) Apr 7, 2019
ReactElementValidator.js Provide new jsx transform target for reactjs/rfcs#107 (#15141) Apr 7, 2019
ReactHooks.js Add more info to invalid hook call error message (#15139) Mar 18, 2019
ReactLazy.js Validate propTypes for lazy() and memo() and warn about invalid patte… Nov 29, 2018
ReactNoopUpdateQueue.js Drop the year from Facebook copyright headers and the LICENSE file. (#… Sep 7, 2018
ReactSharedInternals.js Add withSuspenseConfig API (#15593) May 16, 2019
forwardRef.js Warn for forwardRef(memo(...)) (#14070) Nov 2, 2018
memo.js pure -> memo (#13905) Oct 20, 2018
withComponentStack.js
You can’t perform that action at this time.