Skip to content

Commit

Permalink
fix: don't track pathname access as dynamic when in dev from dev overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed Oct 16, 2024
1 parent 89b23fd commit 5981511
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ReactNode } from 'react'
import { useCallback, useEffect, startTransition, useMemo, useRef } from 'react'
import stripAnsi from 'next/dist/compiled/strip-ansi'
import formatWebpackMessages from '../internal/helpers/format-webpack-messages'
import { usePathname, useRouter } from '../../navigation'
import { useRouter } from '../../navigation'
import {
ACTION_BEFORE_REFRESH,
ACTION_BUILD_ERROR,
Expand Down Expand Up @@ -36,6 +36,7 @@ import { extractModulesFromTurbopackMessage } from '../../../../server/dev/extra
import { REACT_REFRESH_FULL_RELOAD_FROM_ERROR } from '../shared'
import type { HydrationErrorState } from '../internal/helpers/hydration-error-info'
import type { DebugInfo } from '../types'
import { useUntrackedPathname } from '../../navigation-untracked'

export interface Dispatcher {
onBuildOk(): void
Expand Down Expand Up @@ -598,7 +599,10 @@ export default function HotReload({
)

const router = useRouter()
const pathname = usePathname()

// We don't want access of the pathname for the dev tools to trigger a dynamic
// access (as the dev overlay will never be present in production).
const pathname = useUntrackedPathname()
const appIsrManifestRef = useRef<Record<string, false | number>>({})
const pathnameRef = useRef(pathname)

Expand All @@ -612,7 +616,7 @@ export default function HotReload({
const appIsrManifest = appIsrManifestRef.current

if (appIsrManifest) {
if (pathname in appIsrManifest) {
if (pathname && pathname in appIsrManifest) {
const indicatorHiddenAt = Number(
localStorage?.getItem('__NEXT_DISMISS_PRERENDER_INDICATOR')
)
Expand Down

0 comments on commit 5981511

Please sign in to comment.