Skip to content

Commit

Permalink
Update LAZYINITIALIZED/DATAFETCH to have underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Nov 11, 2022
1 parent 974fe29 commit 540782e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
6 changes: 3 additions & 3 deletions packages/next/client/components/app-router.tsx
Expand Up @@ -180,7 +180,7 @@ function Router({
previousTree,
overrideCanonicalUrl,
cache: {
status: CacheStates.LAZYINITIALIZED,
status: CacheStates.LAZY_INITIALIZED,
data: null,
subTreeData: null,
parallelRoutes: new Map(),
Expand All @@ -206,7 +206,7 @@ function Router({
forceOptimisticNavigation,
navigateType,
cache: {
status: CacheStates.LAZYINITIALIZED,
status: CacheStates.LAZY_INITIALIZED,
data: null,
subTreeData: null,
parallelRoutes: new Map(),
Expand Down Expand Up @@ -268,7 +268,7 @@ function Router({

// TODO-APP: revisit if this needs to be passed.
cache: {
status: CacheStates.LAZYINITIALIZED,
status: CacheStates.LAZY_INITIALIZED,
data: null,
subTreeData: null,
parallelRoutes: new Map(),
Expand Down
4 changes: 2 additions & 2 deletions packages/next/client/components/layout-router.tsx
Expand Up @@ -146,7 +146,7 @@ export function InnerLayoutRouter({
// TODO-APP: verify if this can be null based on user code
childProp.current !== null
) {
if (childNode && childNode.status === CacheStates.LAZYINITIALIZED) {
if (childNode && childNode.status === CacheStates.LAZY_INITIALIZED) {
// @ts-expect-error TODO-APP: handle changing of the type
childNode.status = CacheStates.READY
// @ts-expect-error TODO-APP: handle changing of the type
Expand Down Expand Up @@ -181,7 +181,7 @@ export function InnerLayoutRouter({
* Flight data fetch kicked off during render and put into the cache.
*/
childNodes.set(path, {
status: CacheStates.DATAFETCH,
status: CacheStates.DATA_FETCH,
data: fetchServerResponse(new URL(url, location.origin), refetchTree),
subTreeData: null,
parallelRoutes: new Map(),
Expand Down
19 changes: 11 additions & 8 deletions packages/next/client/components/reducer.ts
Expand Up @@ -99,7 +99,7 @@ function fillLazyItemsTillLeafWithHead(
let parallelRouteCacheNode = new Map(existingParallelRoutesCacheNode)
parallelRouteCacheNode.delete(cacheKey)
const newCacheNode: CacheNode = {
status: CacheStates.LAZYINITIALIZED,
status: CacheStates.LAZY_INITIALIZED,
data: null,
subTreeData: null,
parallelRoutes: new Map(),
Expand All @@ -118,7 +118,7 @@ function fillLazyItemsTillLeafWithHead(
}

const newCacheNode: CacheNode = {
status: CacheStates.LAZYINITIALIZED,
status: CacheStates.LAZY_INITIALIZED,
data: null,
subTreeData: null,
parallelRoutes: new Map(),
Expand Down Expand Up @@ -292,7 +292,7 @@ function fillCacheWithPrefetchedSubTreeData(
existingCache: CacheNode,
flightDataPath: FlightDataPath
): void {
const isLastEntry = flightDataPath.length <= 4
const isLastEntry = flightDataPath.length <= 5
const [parallelRouteKey, segment] = flightDataPath

const segmentForCache = Array.isArray(segment) ? segment[1] : segment
Expand Down Expand Up @@ -372,7 +372,7 @@ function fillCacheWithDataProperty(
childCacheNode === existingChildCacheNode
) {
childSegmentMap.set(segment, {
status: CacheStates.DATAFETCH,
status: CacheStates.DATA_FETCH,
data: fetchResponse(),
subTreeData: null,
parallelRoutes: new Map(),
Expand All @@ -385,7 +385,7 @@ function fillCacheWithDataProperty(
// Start fetch in the place where the existing cache doesn't have the data yet.
if (!childCacheNode) {
childSegmentMap.set(segment, {
status: CacheStates.DATAFETCH,
status: CacheStates.DATA_FETCH,
data: fetchResponse(),
subTreeData: null,
parallelRoutes: new Map(),
Expand Down Expand Up @@ -997,6 +997,7 @@ function clientReducer(
const flightDataPath = flightData[0]

// The one before last item is the router state tree patch
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [treePatch, subTreeData, head] = flightDataPath.slice(-3)

// Path without the last segment, router state, and the subTreeData
Expand Down Expand Up @@ -1123,6 +1124,7 @@ function clientReducer(

// Slices off the last segment (which is at -4) as it doesn't exist in the tree yet
const flightSegmentPath = flightDataPath.slice(0, -4)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [treePatch, subTreeData, head] = flightDataPath.slice(-3)

const newTree = applyRouterStatePatchToTree(
Expand Down Expand Up @@ -1267,7 +1269,7 @@ function clientReducer(
const flightDataPath = flightData[0]

// FlightDataPath with more than two items means unexpected Flight data was returned
if (flightDataPath.length !== 2) {
if (flightDataPath.length !== 3) {
// TODO-APP: handle this case better
console.log('REFRESH FAILED')
return state
Expand Down Expand Up @@ -1332,15 +1334,16 @@ function clientReducer(
const flightDataPath = flightData[0]

// The one before last item is the router state tree patch
const [treePatch, subTreeData] = flightDataPath.slice(-2)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [treePatch, subTreeData, head] = flightDataPath.slice(-3)

// TODO-APP: Verify if `null` can't be returned from user code.
// If subTreeData is null the prefetch did not provide a component tree.
if (subTreeData !== null) {
fillCacheWithPrefetchedSubTreeData(state.cache, flightDataPath)
}

const flightSegmentPath = flightDataPath.slice(0, -2)
const flightSegmentPath = flightDataPath.slice(0, -3)

const newTree = applyRouterStatePatchToTree(
// TODO-APP: remove ''
Expand Down
8 changes: 4 additions & 4 deletions packages/next/shared/lib/app-router-context.ts
Expand Up @@ -8,8 +8,8 @@ export type ChildSegmentMap = Map<string, CacheNode>

// eslint-disable-next-line no-shadow
export enum CacheStates {
LAZYINITIALIZED = 'LAZYINITIALIZED',
DATAFETCH = 'DATAFETCH',
LAZY_INITIALIZED = 'LAZYINITIALIZED',
DATA_FETCH = 'DATAFETCH',
READY = 'READY',
}

Expand All @@ -18,7 +18,7 @@ export enum CacheStates {
*/
export type CacheNode =
| {
status: CacheStates.DATAFETCH
status: CacheStates.DATA_FETCH
/**
* In-flight request for this node.
*/
Expand Down Expand Up @@ -52,7 +52,7 @@ export type CacheNode =
parallelRoutes: Map<string, ChildSegmentMap>
}
| {
status: CacheStates.LAZYINITIALIZED
status: CacheStates.LAZY_INITIALIZED
data: null
head?: React.ReactNode
subTreeData: null
Expand Down

0 comments on commit 540782e

Please sign in to comment.