GeezerVison is showing github.com — Add built-in Suspense cache with support for invalidation (refreshing… · react/react@efc57e5
File treeExpand file treeCollapse file tree Open diff view settings react-suspense-test-utils/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/server/ReactPartialRendererHooks.js +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -489,6 +489,10 @@ function useOpaqueIdentifier(): OpaqueIDType { | 489 | 489 | ); | 490 | 490 | } | 491 | 491 |
| | 492 | +function useCacheRefresh(): <T>(?() => T, ?T) => void { | | 493 | + invariant(false, 'Not implemented.'); | | 494 | +} | | 495 | + | 492 | 496 | function noop(): void {} | 493 | 497 |
| 494 | 498 | export let currentPartialRenderer: PartialRenderer = (null: any); | @@ -520,4 +524,5 @@ export const Dispatcher: DispatcherType = { | 520 | 524 |
| 521 | 525 | if (enableCache) { | 522 | 526 | Dispatcher.getCacheForType = getCacheForType; | | 527 | + Dispatcher.useCacheRefresh = useCacheRefresh; | 523 | 528 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiber.new.js +26Lines changed: 26 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,6 +27,7 @@ import { | 27 | 27 | enableProfilerTimer, | 28 | 28 | enableFundamentalAPI, | 29 | 29 | enableScopeAPI, | | 30 | + enableCache, | 30 | 31 | } from 'shared/ReactFeatureFlags'; | 31 | 32 | import {NoFlags, Placement, StaticMask} from './ReactFiberFlags'; | 32 | 33 | import {ConcurrentRoot, BlockingRoot} from './ReactRootTags'; | @@ -54,6 +55,7 @@ import { | 54 | 55 | ScopeComponent, | 55 | 56 | OffscreenComponent, | 56 | 57 | LegacyHiddenComponent, | | 58 | + CacheComponent, | 57 | 59 | } from './ReactWorkTags'; | 58 | 60 | import getComponentName from 'shared/getComponentName'; | 59 | 61 |
| @@ -88,6 +90,7 @@ import { | 88 | 90 | REACT_SCOPE_TYPE, | 89 | 91 | REACT_OFFSCREEN_TYPE, | 90 | 92 | REACT_LEGACY_HIDDEN_TYPE, | | 93 | + REACT_CACHE_TYPE, | 91 | 94 | } from 'shared/ReactSymbols'; | 92 | 95 |
| 93 | 96 | export type {Fiber}; | @@ -501,6 +504,11 @@ export function createFiberFromTypeAndProps( | 501 | 504 | return createFiberFromScope(type, pendingProps, mode, lanes, key); | 502 | 505 | } | 503 | 506 | // eslint-disable-next-line no-fallthrough | | 507 | + case REACT_CACHE_TYPE: | | 508 | + if (enableCache) { | | 509 | + return createFiberFromCache(pendingProps, mode, lanes, key); | | 510 | + } | | 511 | + // eslint-disable-next-line no-fallthrough | 504 | 512 | default: { | 505 | 513 | if (typeof type === 'object' && type !== null) { | 506 | 514 | switch (type.$$typeof) { | @@ -745,6 +753,24 @@ export function createFiberFromLegacyHidden( | 745 | 753 | return fiber; | 746 | 754 | } | 747 | 755 |
| | 756 | +export function createFiberFromCache( | | 757 | + pendingProps: any, | | 758 | + mode: TypeOfMode, | | 759 | + lanes: Lanes, | | 760 | + key: null | string, | | 761 | +) { | | 762 | + const fiber = createFiber(CacheComponent, pendingProps, key, mode); | | 763 | + // TODO: The Cache fiber shouldn't have a type. It has a tag. | | 764 | + // This needs to be fixed in getComponentName so that it relies on the tag | | 765 | + // instead. | | 766 | + if (__DEV__) { | | 767 | + fiber.type = REACT_CACHE_TYPE; | | 768 | + } | | 769 | + fiber.elementType = REACT_CACHE_TYPE; | | 770 | + fiber.lanes = lanes; | | 771 | + return fiber; | | 772 | +} | | 773 | + | 748 | 774 | export function createFiberFromText( | 749 | 775 | content: string, | 750 | 776 | mode: TypeOfMode, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiber.old.js +26Lines changed: 26 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,6 +27,7 @@ import { | 27 | 27 | enableProfilerTimer, | 28 | 28 | enableFundamentalAPI, | 29 | 29 | enableScopeAPI, | | 30 | + enableCache, | 30 | 31 | } from 'shared/ReactFeatureFlags'; | 31 | 32 | import {NoFlags, Placement, StaticMask} from './ReactFiberFlags'; | 32 | 33 | import {ConcurrentRoot, BlockingRoot} from './ReactRootTags'; | @@ -54,6 +55,7 @@ import { | 54 | 55 | ScopeComponent, | 55 | 56 | OffscreenComponent, | 56 | 57 | LegacyHiddenComponent, | | 58 | + CacheComponent, | 57 | 59 | } from './ReactWorkTags'; | 58 | 60 | import getComponentName from 'shared/getComponentName'; | 59 | 61 |
| @@ -88,6 +90,7 @@ import { | 88 | 90 | REACT_SCOPE_TYPE, | 89 | 91 | REACT_OFFSCREEN_TYPE, | 90 | 92 | REACT_LEGACY_HIDDEN_TYPE, | | 93 | + REACT_CACHE_TYPE, | 91 | 94 | } from 'shared/ReactSymbols'; | 92 | 95 |
| 93 | 96 | export type {Fiber}; | @@ -501,6 +504,11 @@ export function createFiberFromTypeAndProps( | 501 | 504 | return createFiberFromScope(type, pendingProps, mode, lanes, key); | 502 | 505 | } | 503 | 506 | // eslint-disable-next-line no-fallthrough | | 507 | + case REACT_CACHE_TYPE: | | 508 | + if (enableCache) { | | 509 | + return createFiberFromCache(pendingProps, mode, lanes, key); | | 510 | + } | | 511 | + // eslint-disable-next-line no-fallthrough | 504 | 512 | default: { | 505 | 513 | if (typeof type === 'object' && type !== null) { | 506 | 514 | switch (type.$$typeof) { | @@ -745,6 +753,24 @@ export function createFiberFromLegacyHidden( | 745 | 753 | return fiber; | 746 | 754 | } | 747 | 755 |
| | 756 | +export function createFiberFromCache( | | 757 | + pendingProps: any, | | 758 | + mode: TypeOfMode, | | 759 | + lanes: Lanes, | | 760 | + key: null | string, | | 761 | +) { | | 762 | + const fiber = createFiber(CacheComponent, pendingProps, key, mode); | | 763 | + // TODO: The Cache fiber shouldn't have a type. It has a tag. | | 764 | + // This needs to be fixed in getComponentName so that it relies on the tag | | 765 | + // instead. | | 766 | + if (__DEV__) { | | 767 | + fiber.type = REACT_CACHE_TYPE; | | 768 | + } | | 769 | + fiber.elementType = REACT_CACHE_TYPE; | | 770 | + fiber.lanes = lanes; | | 771 | + return fiber; | | 772 | +} | | 773 | + | 748 | 774 | export function createFiberFromText( | 749 | 775 | content: string, | 750 | 776 | mode: TypeOfMode, | |
|