Skip to content

Commit

Permalink
Revert "Add experimental config for navigation raf test (#62668)" (#6…
Browse files Browse the repository at this point in the history
…2834)

Reverting this experimental flag as it should not be used and we are
going to investigate experimenting with this further upstream so that it
can be done properly.

This reverts commit 2bdcaa0.

x-ref: #62668



Closes NEXT-2689
  • Loading branch information
ijjk authored Mar 4, 2024
1 parent 6e89226 commit 5717b9a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 64 deletions.
3 changes: 0 additions & 3 deletions packages/next/src/build/webpack/plugins/define-env-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ export function getDefineEnv({
'process.env.__NEXT_NO_MIDDLEWARE_URL_NORMALIZE': JSON.stringify(
config.skipMiddlewareUrlNormalize
),
'process.env.__NEXT_NAVIGATION_RAF': JSON.stringify(
config.experimental.navigationRAF
),
'process.env.__NEXT_EXTERNAL_MIDDLEWARE_REWRITE_RESOLVE': JSON.stringify(
config.experimental.externalMiddlewareRewritesResolve
),
Expand Down
41 changes: 9 additions & 32 deletions packages/next/src/client/components/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,38 +225,15 @@ function useChangeByServerResponse(
function useNavigate(dispatch: React.Dispatch<ReducerActions>): RouterNavigate {
return useCallback(
(href, navigateType, shouldScroll) => {
const navigateWrapper = process.env.__NEXT_NAVIGATION_RAF
? (cb: () => void) => {
let finished = false

// if the frame is hidden or requestAnimationFrame
// is delayed too long add upper bound timeout
setTimeout(() => {
if (!finished) {
finished = true
cb()
}
}, 1000)
requestAnimationFrame(() => {
setTimeout(() => {
finished = true
cb()
}, 1)
})
}
: (cb: () => void) => cb()

navigateWrapper(() => {
const url = new URL(addBasePath(href), location.href)

return dispatch({
type: ACTION_NAVIGATE,
url,
isExternalUrl: isExternalURL(url),
locationSearch: location.search,
shouldScroll: shouldScroll ?? true,
navigateType,
})
const url = new URL(addBasePath(href), location.href)

return dispatch({
type: ACTION_NAVIGATE,
url,
isExternalUrl: isExternalURL(url),
locationSearch: location.search,
shouldScroll: shouldScroll ?? true,
navigateType,
})
},
[dispatch]
Expand Down
1 change: 0 additions & 1 deletion packages/next/src/server/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
manualClientBasePath: z.boolean().optional(),
middlewarePrefetch: z.enum(['strict', 'flexible']).optional(),
mergeCssChunks: z.boolean().optional(),
navigationRAF: z.boolean().optional(),
nextScriptWorkers: z.boolean().optional(),
// The critter option is unknown, use z.any() here
optimizeCss: z.union([z.boolean(), z.any()]).optional(),
Expand Down
2 changes: 0 additions & 2 deletions packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ export interface NextJsWebpackConfig {
}

export interface ExperimentalConfig {
navigationRAF?: boolean
prerenderEarlyExit?: boolean
linkNoTouchStart?: boolean
caseSensitiveRoutes?: boolean
Expand Down Expand Up @@ -844,7 +843,6 @@ export const defaultConfig: NextConfig = {
output: !!process.env.NEXT_PRIVATE_STANDALONE ? 'standalone' : undefined,
modularizeImports: undefined,
experimental: {
navigationRAF: false,
prerenderEarlyExit: false,
serverMinification: true,
serverSourceMaps: false,
Expand Down
40 changes: 14 additions & 26 deletions packages/next/src/shared/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1498,32 +1498,20 @@ export default class Router implements BaseRouter {
const isErrorRoute = this.pathname === '/404' || this.pathname === '/_error'

try {
let [routeInfo] = await Promise.all([
this.getRouteInfo({
route,
pathname,
query,
as,
resolvedAs,
routeProps,
locale: nextState.locale,
isPreview: nextState.isPreview,
hasMiddleware: isMiddlewareMatch,
unstable_skipClientCache: options.unstable_skipClientCache,
isQueryUpdating: isQueryUpdating && !this.isFallback,
isMiddlewareRewrite,
}),
process.env.__NEXT_NAVIGATION_RAF
? new Promise((resolve) => {
// if the frame is hidden or requestAnimationFrame
// is delayed too long add upper bound timeout
setTimeout(resolve, 1000)
requestAnimationFrame(() => {
setTimeout(resolve, 1)
})
})
: Promise.resolve(),
])
let routeInfo = await this.getRouteInfo({
route,
pathname,
query,
as,
resolvedAs,
routeProps,
locale: nextState.locale,
isPreview: nextState.isPreview,
hasMiddleware: isMiddlewareMatch,
unstable_skipClientCache: options.unstable_skipClientCache,
isQueryUpdating: isQueryUpdating && !this.isFallback,
isMiddlewareRewrite,
})

if (!isQueryUpdating && !options.shallow) {
await this._bfl(
Expand Down

0 comments on commit 5717b9a

Please sign in to comment.