From 675be10c9b822475e00f40285a0a2be4a2bfb246 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Tue, 12 Jul 2022 16:44:23 +0200 Subject: [PATCH] Rename todos --- packages/next/build/entries.ts | 2 +- packages/next/client/app-next-dev.js | 6 ++-- .../client/components/app-router.client.tsx | 12 +++---- .../next/client/components/hooks-client.ts | 6 ++-- .../client/components/hot-reloader.client.tsx | 14 ++++---- .../components/layout-router.client.tsx | 12 +++---- packages/next/client/components/reducer.ts | 26 +++++++------- packages/next/client/link.tsx | 4 +-- packages/next/lib/app-layout.tsx | 17 --------- packages/next/server/app-render.tsx | 36 +++++++++---------- 10 files changed, 59 insertions(+), 76 deletions(-) delete mode 100644 packages/next/lib/app-layout.tsx diff --git a/packages/next/build/entries.ts b/packages/next/build/entries.ts index aa9b46b4f2d4..88a0f01f6935 100644 --- a/packages/next/build/entries.ts +++ b/packages/next/build/entries.ts @@ -510,7 +510,7 @@ export function finalizeEntrypoint({ name !== CLIENT_STATIC_FILES_RUNTIME_AMP && name !== CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH ) { - // TODO: this is a temporary fix. @shuding is going to change the handling of server components + // TODO-APP: this is a temporary fix. @shuding is going to change the handling of server components if (appDir && entry.import.includes('flight')) { return { dependOn: CLIENT_STATIC_FILES_RUNTIME_MAIN_ROOT, diff --git a/packages/next/client/app-next-dev.js b/packages/next/client/app-next-dev.js index 842c553d801e..1ab8210e8337 100644 --- a/packages/next/client/app-next-dev.js +++ b/packages/next/client/app-next-dev.js @@ -1,8 +1,8 @@ import { hydrate, version } from './app-index' -// TODO: implement FOUC guard +// TODO-APP: implement FOUC guard -// TODO: hydration warning +// TODO-APP: hydration warning window.next = { version, @@ -11,4 +11,4 @@ window.next = { hydrate() -// TODO: build indicator +// TODO-APP: build indicator diff --git a/packages/next/client/components/app-router.client.tsx b/packages/next/client/components/app-router.client.tsx index 7dc6e8bffd93..cf5eeb2ad108 100644 --- a/packages/next/client/components/app-router.client.tsx +++ b/packages/next/client/components/app-router.client.tsx @@ -49,7 +49,7 @@ function ErrorOverlay({ } } -// TODO: move this back into AppRouter +// TODO-APP: move this back into AppRouter let initialParallelRoutes: CacheNode['parallelRoutes'] = typeof window === 'undefined' ? null! : new Map() @@ -136,7 +136,7 @@ export default function AppRouter({ } const routerInstance: AppRouterInstance = { - // TODO: implement prefetching of loading / flight + // TODO-APP: implement prefetching of loading / flight prefetch: (_href) => Promise.resolve(), replace: (href) => { // @ts-ignore startTransition exists @@ -168,7 +168,7 @@ export default function AppRouter({ dispatch({ type: 'reload', payload: { - // TODO: revisit if this needs to be passed. + // TODO-APP: revisit if this needs to be passed. url: new URL(window.location.href), cache: { data: null, @@ -211,11 +211,11 @@ export default function AppRouter({ const onPopState = React.useCallback(({ state }: PopStateEvent) => { if (!state) { - // TODO: this case only happens when pushState/replaceState was called outside of Next.js. It should probably reload the page in this case. + // TODO-APP: this case only happens when pushState/replaceState was called outside of Next.js. It should probably reload the page in this case. return } - // TODO: this case happens when pushState/replaceState was called outside of Next.js or when the history entry was pushed by the old router. + // TODO-APP: this case happens when pushState/replaceState was called outside of Next.js or when the history entry was pushed by the old router. // It reloads the page in this case but we might have to revisit this as the old router ignores it. if (!state.__NA) { window.location.reload() @@ -223,7 +223,7 @@ export default function AppRouter({ } // @ts-ignore useTransition exists - // TODO: Ideally the back button should not use startTransition as it should apply the updates synchronously + // TODO-APP: Ideally the back button should not use startTransition as it should apply the updates synchronously // Without startTransition works if the cache is there for this path React.startTransition(() => { dispatch({ diff --git a/packages/next/client/components/hooks-client.ts b/packages/next/client/components/hooks-client.ts index 5a43d87dd94e..aad1971a811a 100644 --- a/packages/next/client/components/hooks-client.ts +++ b/packages/next/client/components/hooks-client.ts @@ -21,12 +21,12 @@ export function useSearchParam(key: string) { return params[key] } -// TODO: Move the other router context over to this one +// TODO-APP: Move the other router context over to this one export function useRouter() { return useContext(AppRouterContext) } -// TODO: getting all params when client-side navigating is non-trivial as it does not have route matchers so this might have to be a server context instead. +// TODO-APP: getting all params when client-side navigating is non-trivial as it does not have route matchers so this might have to be a server context instead. // export function useParams() { // return useContext(ParamsContext) // } @@ -35,7 +35,7 @@ export function usePathname() { return useContext(PathnameContext) } -// TODO: define what should be provided through context. +// TODO-APP: define what should be provided through context. // export function useLayoutSegments() { // return useContext(LayoutSegmentsContext) // } diff --git a/packages/next/client/components/hot-reloader.client.tsx b/packages/next/client/components/hot-reloader.client.tsx index a431c723d598..00092175e842 100644 --- a/packages/next/client/components/hot-reloader.client.tsx +++ b/packages/next/client/components/hot-reloader.client.tsx @@ -3,7 +3,7 @@ import { useContext, useEffect, useRef, - // @ts-expect-error TODO: startTransition exists + // @ts-expect-error TODO-APP: startTransition exists startTransition, } from 'react' import { FullAppTreeContext } from '../../shared/lib/app-router-context' @@ -31,7 +31,7 @@ function getSocketProtocol(assetPrefix: string): string { // const TIMEOUT = 5000 -// TODO: add actual type +// TODO-APP: add actual type type PongEvent = any let mostRecentCompilationHash: any = null @@ -305,7 +305,7 @@ function processMessage( } return } - // TODO: make server component change more granular + // TODO-APP: make server component change more granular case 'serverComponentChanges': { sendMessage( JSON.stringify({ @@ -375,7 +375,7 @@ function processMessage( // Page exists now, reload location.reload() } else { - // TODO: fix this + // TODO-APP: fix this // Page doesn't exist // if ( // self.__NEXT_DATA__.page === Router.pathname && @@ -442,12 +442,12 @@ export default function HotReload({ assetPrefix }: { assetPrefix: string }) { }, [assetPrefix]) useEffect(() => { // Taken from on-demand-entries-client.js - // TODO: check 404 case + // TODO-APP: check 404 case const interval = setInterval(() => { sendMessage( JSON.stringify({ event: 'ping', - // TODO: fix case for dynamic parameters, this will be resolved wrong currently. + // TODO-APP: fix case for dynamic parameters, this will be resolved wrong currently. tree, appDirRoute: true, }) @@ -459,7 +459,7 @@ export default function HotReload({ assetPrefix }: { assetPrefix: string }) { const handler = (event: MessageEvent) => { if ( event.data.indexOf('action') === -1 && - // TODO: clean this up for consistency + // TODO-APP: clean this up for consistency event.data.indexOf('pong') === -1 ) { return diff --git a/packages/next/client/components/layout-router.client.tsx b/packages/next/client/components/layout-router.client.tsx index e24c10adc6fd..92376c54ec4e 100644 --- a/packages/next/client/components/layout-router.client.tsx +++ b/packages/next/client/components/layout-router.client.tsx @@ -123,7 +123,7 @@ export function InnerLayoutRouter({ return treeToRecreate } - // TODO: remove '' + // TODO-APP: remove '' const refetchTree = walkAddRefetch(['', ...segmentPath], fullTree) const data = fetchServerResponse(new URL(url, location.origin), refetchTree) @@ -148,7 +148,7 @@ export function InnerLayoutRouter({ } if (childNode.data) { - // TODO: error case + // TODO-APP: error case const flightData = childNode.data.readRoot() // Handle case when navigating to page in `pages` from `app` @@ -165,7 +165,7 @@ export function InnerLayoutRouter({ if (pathMatches(flightDataPath, segmentPath)) { childNode.data = null // Last item is the subtreeData - // TODO: routerTreePatch needs to be applied to the tree, handle it in render? + // TODO-APP: routerTreePatch needs to be applied to the tree, handle it in render? const [, /* routerTreePatch */ subTreeData] = flightDataPath.slice(-2) childNode.subTreeData = subTreeData childNode.parallelRoutes = new Map() @@ -182,7 +182,7 @@ export function InnerLayoutRouter({ setTimeout(() => { // @ts-ignore startTransition exists React.startTransition(() => { - // TODO: handle redirect + // TODO-APP: handle redirect changeByServerResponse(fullTree, flightData) }) }) @@ -191,7 +191,7 @@ export function InnerLayoutRouter({ } } - // TODO: double check users can't return null in a component that will kick in here + // TODO-APP: double check users can't return null in a component that will kick in here if (!childNode.subTreeData) { throw createInfinitePromise() } @@ -201,7 +201,7 @@ export function InnerLayoutRouter({ value={{ tree: tree[1][parallelRouterKey], childNodes: childNode.parallelRoutes, - // TODO: overriding of url for parallel routes + // TODO-APP: overriding of url for parallel routes url: url, }} > diff --git a/packages/next/client/components/reducer.ts b/packages/next/client/components/reducer.ts index 08b4cee164de..f7afa1e4e8fa 100644 --- a/packages/next/client/components/reducer.ts +++ b/packages/next/client/components/reducer.ts @@ -12,7 +12,7 @@ const fillCacheWithNewSubTreeData = ( existingCache: CacheNode, flightDataPath: FlightDataPath ) => { - // TODO: handle case of / (root of the tree) refetch + // TODO-APP: handle case of / (root of the tree) refetch const isLastEntry = flightDataPath.length <= 4 const [parallelRouteKey, segment] = flightDataPath @@ -224,7 +224,7 @@ const walkTreeWithFlightDataPath = ( const [currentSegment, parallelRouteKey] = flightSegmentPath // Tree path returned from the server should always match up with the current tree in the browser - // TODO: verify + // TODO-APP: verify if (!matchSegment(currentSegment, segment)) { throw new Error('SEGMENT MISMATCH') } @@ -315,7 +315,7 @@ export function reducer( const href = url.pathname + url.search + url.hash const segments = pathname.split('/') - // TODO: figure out something better for index pages + // TODO-APP: figure out something better for index pages segments.push('') // In case of soft push data fetching happens in layout-router if a segment is missing @@ -352,7 +352,7 @@ export function reducer( } } - // TODO: flag on the tree of which part of the tree for if there is a loading boundary + // TODO-APP: flag on the tree of which part of the tree for if there is a loading boundary const isOptimistic = false if (isOptimistic) { @@ -367,7 +367,7 @@ export function reducer( ) // Fill in the cache with blank that holds the `data` field. - // TODO: segments.slice(1) strips '', we can get rid of '' altogether. + // TODO-APP: segments.slice(1) strips '', we can get rid of '' altogether. const res = fillCacheWithDataProperty( cache, state.cache, @@ -406,13 +406,13 @@ export function reducer( cache.data = null - // TODO: ensure flightDataPath does not have "" as first item + // TODO-APP: ensure flightDataPath does not have "" as first item const flightDataPath = flightData[0] const [treePatch] = flightDataPath.slice(-2) const treePath = flightDataPath.slice(0, -3) const newTree = walkTreeWithFlightDataPath( - // TODO: remove '' + // TODO-APP: remove '' ['', ...treePath], state.tree, treePatch @@ -438,7 +438,7 @@ export function reducer( if (action.type === 'server-patch') { const { flightData, previousTree, cache } = action.payload if (JSON.stringify(previousTree) !== JSON.stringify(state.tree)) { - // TODO: Handle tree mismatch + // TODO-APP: Handle tree mismatch console.log('TREE MISMATCH') return { canonicalUrl: state.canonicalUrl, @@ -458,7 +458,7 @@ export function reducer( } } - // TODO: flightData could hold multiple paths + // TODO-APP: flightData could hold multiple paths const flightDataPath = flightData[0] // Slices off the last segment (which is at -3) as it doesn't exist in the tree yet @@ -466,7 +466,7 @@ export function reducer( const [treePatch] = flightDataPath.slice(-2) const newTree = walkTreeWithFlightDataPath( - // TODO: remove '' + // TODO-APP: remove '' ['', ...treePath], state.tree, treePatch @@ -526,18 +526,18 @@ export function reducer( cache.data = null - // TODO: ensure flightDataPath does not have "" as first item + // TODO-APP: ensure flightDataPath does not have "" as first item const flightDataPath = flightData[0] if (flightDataPath.length !== 2) { - // TODO: handle this case better + // TODO-APP: handle this case better console.log('RELOAD FAILED') return state } const [treePatch, subTreeData] = flightDataPath.slice(-2) const newTree = walkTreeWithFlightDataPath( - // TODO: remove '' + // TODO-APP: remove '' [''], state.tree, treePatch diff --git a/packages/next/client/link.tsx b/packages/next/client/link.tsx index 4ddc17a2b5c2..5477b7e4867b 100644 --- a/packages/next/client/link.tsx +++ b/packages/next/client/link.tsx @@ -46,7 +46,7 @@ type InternalLinkProps = { onClick?: (e: any) => void } -// TODO: Include the full set of Anchor props +// TODO-APP: Include the full set of Anchor props // adding this to the publicly exported type currently breaks existing apps export type LinkProps = InternalLinkProps type LinkPropsRequired = RequiredKeys @@ -292,7 +292,7 @@ const Link = React.forwardRef( : [] let router = React.useContext(RouterContext) - // TODO: type error. Remove `as any` + // TODO-APP: type error. Remove `as any` const appRouter = React.useContext(AppRouterContext) as any if (appRouter) { router = appRouter diff --git a/packages/next/lib/app-layout.tsx b/packages/next/lib/app-layout.tsx deleted file mode 100644 index b88bd0c2b499..000000000000 --- a/packages/next/lib/app-layout.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import React from 'react' - -export type LayoutProps = { - children: any -} - -export default function AppLayout({ children }: LayoutProps) { - return ( - - - {/* TODO: Remove */} - <title>Test - - {children} - - ) -} diff --git a/packages/next/server/app-render.tsx b/packages/next/server/app-render.tsx index 538adc025a8e..898dd59c848f 100644 --- a/packages/next/server/app-render.tsx +++ b/packages/next/server/app-render.tsx @@ -385,9 +385,9 @@ export async function renderToHTML( ) } - // TODO: verify the tree is valid - // TODO: verify query param is single value (not an array) - // TODO: verify tree can't grow out of control + // TODO-APP: verify the tree is valid + // TODO-APP: verify query param is single value (not an array) + // TODO-APP: verify tree can't grow out of control const providedFlightRouterState: FlightRouterState = isFlight ? query.__flight_router_state_tree__ ? JSON.parse(query.__flight_router_state_tree__ as string) @@ -406,7 +406,7 @@ export async function renderToHTML( | null const headers = req.headers - // @ts-expect-error TODO: fix type of req + // @ts-expect-error TODO-APP: fix type of req const cookies = req.cookies const tree: LoaderTree = ComponentMod.tree @@ -421,7 +421,7 @@ export async function renderToHTML( ) const isPreview = previewData !== false const serverContexts: Array<[string, any]> = [ - ['WORKAROUND', null], // TODO: First value has a bug currently where the value is not set on the second request + ['WORKAROUND', null], // TODO-APP: First value has a bug currently where the value is not set on the second request ['HeadersContext', headers], ['CookiesContext', cookies], ['PreviewDataContext', previewData], @@ -442,7 +442,7 @@ export async function renderToHTML( treeValue: string type: DynamicParamTypesShort } | null => { - // TODO: use correct matching for dynamic routes to get segment param + // TODO-APP: use correct matching for dynamic routes to get segment param const segmentParam = getSegmentParam(segment) if (!segmentParam) { return null @@ -517,7 +517,7 @@ export async function renderToHTML( layoutOrPageMod && !layoutOrPageMod.hasOwnProperty('__next_rsc__') // Only server components can have getServerSideProps / getStaticProps - // TODO: friendly error with correct stacktrace. Potentially this can be part of the compiler instead. + // TODO-APP: friendly error with correct stacktrace. Potentially this can be part of the compiler instead. if (isClientComponentModule) { if (layoutOrPageMod.getServerSideProps) { throw new Error( @@ -602,7 +602,7 @@ export async function renderToHTML( let fetcher: (() => Promise) | null = null type GetServerSidePropsContext = { - // TODO: has to be serializable + // TODO-APP: has to be serializable headers: IncomingHttpHeaders cookies: NextApiRequestCookies layoutSegments: FlightSegmentPath @@ -616,9 +616,9 @@ export async function renderToHTML( pathname: string } - // TODO: pass a shared cache from previous getStaticProps/getServerSideProps calls? + // TODO-APP: pass a shared cache from previous getStaticProps/getServerSideProps calls? if (layoutOrPageMod.getServerSideProps) { - // TODO: recommendation for i18n + // TODO-APP: recommendation for i18n // locales: (renderOpts as any).locales, // always the same // locale: (renderOpts as any).locale, // /nl/something -> nl // defaultLocale: (renderOpts as any).defaultLocale, // changes based on domain @@ -628,7 +628,7 @@ export async function renderToHTML( headers, cookies, layoutSegments: segmentPath, - // TODO: Currently query holds params and pathname is not the actual pathname, it holds the dynamic parameter + // TODO-APP: Currently query holds params and pathname is not the actual pathname, it holds the dynamic parameter ...(isPage ? { query, pathname } : {}), ...(pageIsDynamic ? { params: currentParams } : undefined), ...(isPreview @@ -640,11 +640,11 @@ export async function renderToHTML( layoutOrPageMod.getServerSideProps(getServerSidePropsContext) ) } - // TODO: implement layout specific caching for getStaticProps + // TODO-APP: implement layout specific caching for getStaticProps if (layoutOrPageMod.getStaticProps) { const getStaticPropsContext = { layoutSegments: segmentPath, - // TODO: change this to be URLSearchParams instead? + // TODO-APP: change this to be URLSearchParams instead? ...(isPage ? { pathname } : {}), ...(pageIsDynamic ? { params: currentParams } : undefined), ...(isPreview @@ -686,7 +686,7 @@ export async function renderToHTML( /blog/hello-world/b/c/d -> ['children', 'blog', 'children', ['slug', 'hello-world/b/c/d']] // /blog/[slug] /blog/hello-world -> ['children', 'blog', 'children', ['slug', 'hello-world']] const initialTree = createFlightRouterStateFromLoaderTree(tree)