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

Refactor app-render to decouple type definitions (#47128 #47128

Merged
merged 3 commits into from Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,6 +1,6 @@
import { useEffect, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
import type { FlightRouterState } from '../../server/app-render'
import type { FlightRouterState } from '../../server/app-render/types'

const ANNOUNCER_TYPE = 'next-route-announcer'
const ANNOUNCER_ID = '__next-route-announcer__'
Expand Down
5 changes: 4 additions & 1 deletion packages/next/src/client/components/app-router.tsx
Expand Up @@ -12,7 +12,10 @@ import type {
CacheNode,
AppRouterInstance,
} from '../../shared/lib/app-router-context'
import type { FlightRouterState, FlightData } from '../../server/app-render'
import type {
FlightRouterState,
FlightData,
} from '../../server/app-render/types'
import type { ErrorComponent } from './error-boundary'
import { reducer } from './router-reducer/router-reducer'
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/client/components/layout-router.tsx
Expand Up @@ -8,7 +8,7 @@ import type {
FlightRouterState,
FlightSegmentPath,
ChildProp,
} from '../../server/app-render'
} from '../../server/app-render/types'
import type { ErrorComponent } from './error-boundary'
import { FocusAndScrollRef } from './router-reducer/router-reducer-types'

Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/client/components/match-segments.ts
@@ -1,4 +1,4 @@
import type { Segment } from '../../server/app-render'
import type { Segment } from '../../server/app-render/types'

export const matchSegment = (
existingSegment: Segment,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/client/components/navigation.ts
@@ -1,7 +1,7 @@
// useLayoutSegments() // Only the segments for the current place. ['children', 'dashboard', 'children', 'integrations'] -> /dashboard/integrations (/dashboard/layout.js would get ['children', 'dashboard', 'children', 'integrations'])

import { useContext, useMemo } from 'react'
import type { FlightRouterState } from '../../server/app-render'
import type { FlightRouterState } from '../../server/app-render/types'
import {
AppRouterContext,
LayoutRouterContext,
Expand Down
@@ -1,9 +1,7 @@
import type { AsyncLocalStorage } from 'async_hooks'
import { PreviewData } from '../../../types'
import type {
ReadonlyHeaders,
ReadonlyRequestCookies,
} from '../../server/app-render'
import type { ReadonlyHeaders } from '../../server/app-render/readonly-headers'
import type { ReadonlyRequestCookies } from '../../server/app-render/readonly-request-cookies'
import { createAsyncLocalStorage } from './async-local-storage'

export interface RequestStore {
Expand Down
@@ -1,5 +1,8 @@
import React from 'react'
import type { FlightData, FlightRouterState } from '../../../server/app-render'
import type {
FlightData,
FlightRouterState,
} from '../../../server/app-render/types'
import { applyRouterStatePatchToTree } from './apply-router-state-patch-to-tree'

const getInitialRouterStateTree = (): FlightRouterState => [
Expand Down
@@ -1,7 +1,7 @@
import type {
FlightRouterState,
FlightSegmentPath,
} from '../../../server/app-render'
} from '../../../server/app-render/types'
import { matchSegment } from '../match-segments'

/**
Expand Down
@@ -1,5 +1,5 @@
import React from 'react'
import { FlightRouterState } from '../../../server/app-render'
import type { FlightRouterState } from '../../../server/app-render/types'
import { CacheNode, CacheStates } from '../../../shared/lib/app-router-context'
import { createInitialRouterState } from './create-initial-router-state'

Expand Down
@@ -1,6 +1,6 @@
import type { ReactNode } from 'react'
import type { CacheNode } from '../../../shared/lib/app-router-context'
import type { FlightRouterState } from '../../../server/app-render'
import type { FlightRouterState } from '../../../server/app-render/types'

import { CacheStates } from '../../../shared/lib/app-router-context'
import { createHrefFromUrl } from './create-href-from-url'
Expand Down
@@ -1,5 +1,5 @@
import { createOptimisticTree } from './create-optimistic-tree'
import type { FlightRouterState } from '../../../server/app-render'
import type { FlightRouterState } from '../../../server/app-render/types'

const getInitialRouterStateTree = (): FlightRouterState => [
'',
Expand Down
@@ -1,4 +1,4 @@
import type { FlightRouterState } from '../../../server/app-render'
import type { FlightRouterState } from '../../../server/app-render/types'
import { matchSegment } from '../match-segments'

/**
Expand Down
@@ -1,7 +1,10 @@
'use client'

import { createFromFetch } from 'next/dist/compiled/react-server-dom-webpack/client'
import type { FlightRouterState, FlightData } from '../../../server/app-render'
import type {
FlightRouterState,
FlightData,
} from '../../../server/app-render/types'
import {
NEXT_ROUTER_PREFETCH,
NEXT_ROUTER_STATE_TREE,
Expand Down
@@ -1,7 +1,7 @@
import React from 'react'
import { fillCacheWithNewSubTreeData } from './fill-cache-with-new-subtree-data'
import { CacheStates, CacheNode } from '../../../shared/lib/app-router-context'
import { FlightData } from '../../../server/app-render'
import type { FlightData } from '../../../server/app-render/types'

const getFlightData = (): FlightData => {
return [
Expand Down
@@ -1,5 +1,5 @@
import { CacheNode, CacheStates } from '../../../shared/lib/app-router-context'
import type { FlightDataPath } from '../../../server/app-render'
import type { FlightDataPath } from '../../../server/app-render/types'
import { invalidateCacheByRouterState } from './invalidate-cache-by-router-state'
import { fillLazyItemsTillLeafWithHead } from './fill-lazy-items-till-leaf-with-head'

Expand Down
@@ -1,7 +1,7 @@
import React from 'react'
import { fillLazyItemsTillLeafWithHead } from './fill-lazy-items-till-leaf-with-head'
import { CacheStates, CacheNode } from '../../../shared/lib/app-router-context'
import { FlightData } from '../../../server/app-render'
import type { FlightData } from '../../../server/app-render/types'

const getFlightData = (): FlightData => {
return [
Expand Down
@@ -1,5 +1,5 @@
import { CacheNode, CacheStates } from '../../../shared/lib/app-router-context'
import type { FlightRouterState } from '../../../server/app-render'
import type { FlightRouterState } from '../../../server/app-render/types'

export function fillLazyItemsTillLeafWithHead(
newCache: CacheNode,
Expand Down
@@ -1,5 +1,5 @@
import React from 'react'
import type { FlightData } from '../../../server/app-render'
import type { FlightData } from '../../../server/app-render/types'
import { invalidateCacheBelowFlightSegmentPath } from './invalidate-cache-below-flight-segmentpath'
import { CacheStates, CacheNode } from '../../../shared/lib/app-router-context'
import { fillCacheWithNewSubTreeData } from './fill-cache-with-new-subtree-data'
Expand Down
@@ -1,5 +1,5 @@
import type { CacheNode } from '../../../shared/lib/app-router-context'
import type { FlightSegmentPath } from '../../../server/app-render'
import type { FlightSegmentPath } from '../../../server/app-render/types'

/**
* Fill cache up to the end of the flightSegmentPath, invalidating anything below it.
Expand Down
@@ -1,7 +1,7 @@
import React from 'react'
import { invalidateCacheByRouterState } from './invalidate-cache-by-router-state'
import { CacheStates, CacheNode } from '../../../shared/lib/app-router-context'
import { FlightRouterState } from '../../../server/app-render'
import type { FlightRouterState } from '../../../server/app-render/types'

describe('invalidateCacheByRouterState', () => {
it('should invalidate the cache by router state', () => {
Expand Down
@@ -1,5 +1,5 @@
import type { CacheNode } from '../../../shared/lib/app-router-context'
import type { FlightRouterState } from '../../../server/app-render'
import type { FlightRouterState } from '../../../server/app-render/types'

/**
* Invalidate cache one level down from the router state.
Expand Down
@@ -1,4 +1,4 @@
import type { FlightRouterState } from '../../../server/app-render'
import type { FlightRouterState } from '../../../server/app-render/types'
import { isNavigatingToNewRootLayout } from './is-navigating-to-new-root-layout'

describe('shouldHardNavigate', () => {
Expand Down
@@ -1,4 +1,4 @@
import type { FlightRouterState } from '../../../server/app-render'
import type { FlightRouterState } from '../../../server/app-render/types'

export function isNavigatingToNewRootLayout(
currentTree: FlightRouterState,
Expand Down
@@ -1,5 +1,5 @@
import React from 'react'
import { FlightRouterState } from '../../../../server/app-render'
import type { FlightRouterState } from '../../../../server/app-render/types'
import {
CacheNode,
CacheStates,
Expand Down
@@ -1,4 +1,4 @@
import type { FlightRouterState } from '../../../../server/app-render'
import type { FlightRouterState } from '../../../../server/app-render/types'
import type { ChildSegmentMap } from '../../../../shared/lib/app-router-context'

export function findHeadInCache(
Expand Down
@@ -1,6 +1,6 @@
import React from 'react'
import type { fetchServerResponse as fetchServerResponseType } from '../fetch-server-response'
import type { FlightData } from '../../../../server/app-render'
import type { FlightData } from '../../../../server/app-render/types'
const flightData: FlightData = [
[
'children',
Expand Down Expand Up @@ -68,7 +68,7 @@ jest.mock('../fetch-server-response', () => {
},
}
})
import { FlightRouterState } from '../../../../server/app-render'
import { FlightRouterState } from '../../../../server/app-render/types'
import {
CacheNode,
CacheStates,
Expand Down
Expand Up @@ -5,7 +5,7 @@ import {
import type {
FlightDataPath,
FlightSegmentPath,
} from '../../../../server/app-render'
} from '../../../../server/app-render/types'
import { fetchServerResponse } from '../fetch-server-response'
import { createRecordFromThenable } from '../create-record-from-thenable'
import { readRecordValue } from '../read-record-value'
Expand Down
@@ -1,6 +1,6 @@
import React from 'react'
import type { fetchServerResponse as fetchServerResponseType } from '../fetch-server-response'
import type { FlightData } from '../../../../server/app-render'
import type { FlightData } from '../../../../server/app-render/types'
jest.mock('../fetch-server-response', () => {
const flightData: FlightData = [
[
Expand Down Expand Up @@ -32,7 +32,7 @@ jest.mock('../fetch-server-response', () => {
},
}
})
import { FlightRouterState } from '../../../../server/app-render'
import { FlightRouterState } from '../../../../server/app-render/types'
import {
CacheNode,
CacheStates,
Expand Down
@@ -1,6 +1,6 @@
import React from 'react'
import type { fetchServerResponse } from '../fetch-server-response'
import type { FlightData } from '../../../../server/app-render'
import type { FlightData } from '../../../../server/app-render/types'
jest.mock('../fetch-server-response', () => {
const flightData: FlightData = [
[
Expand Down Expand Up @@ -39,7 +39,7 @@ jest.mock('../fetch-server-response', () => {
},
}
})
import { FlightRouterState } from '../../../../server/app-render'
import { FlightRouterState } from '../../../../server/app-render/types'
import {
CacheNode,
CacheStates,
Expand Down
@@ -1,5 +1,5 @@
import React from 'react'
import { FlightRouterState } from '../../../../server/app-render'
import type { FlightRouterState } from '../../../../server/app-render/types'
import {
CacheNode,
CacheStates,
Expand Down
Expand Up @@ -3,7 +3,7 @@ import type { fetchServerResponse as fetchServerResponseType } from '../fetch-se
import type {
FlightData,
FlightRouterState,
} from '../../../../server/app-render'
} from '../../../../server/app-render/types'
jest.mock('../fetch-server-response', () => {
const flightData: FlightData = [
[
Expand Down
@@ -1,5 +1,8 @@
import type { CacheNode } from '../../../shared/lib/app-router-context'
import type { FlightRouterState, FlightData } from '../../../server/app-render'
import type {
FlightRouterState,
FlightData,
} from '../../../server/app-render/types'
import { fetchServerResponse } from './fetch-server-response'

export const ACTION_REFRESH = 'refresh'
Expand Down
@@ -1,5 +1,8 @@
import React from 'react'
import type { FlightData, FlightRouterState } from '../../../server/app-render'
import type {
FlightData,
FlightRouterState,
} from '../../../server/app-render/types'
import { shouldHardNavigate } from './should-hard-navigate'

describe('shouldHardNavigate', () => {
Expand Down
Expand Up @@ -2,7 +2,7 @@ import type {
FlightRouterState,
FlightDataPath,
Segment,
} from '../../../server/app-render'
} from '../../../server/app-render/types'
import { matchSegment } from '../match-segments'

// TODO-APP: flightSegmentPath will be empty in case of static response, needs to be handled.
Expand Down