Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
5740ef3e
Unverified
Commit
5740ef3e
authored
Mar 07, 2024
by
Balázs Orbán
Committed by
GitHub
Mar 07, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(ts): type `fastRefresh` (#62848)
parent
5f3b1358
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
43 deletions
+31
-43
app-router.tsx
packages/next/src/client/components/app-router.tsx
+0
-1
hot-reloader-client.tsx
.../components/react-dev-overlay/app/hot-reloader-client.tsx
+10
-19
app-router-context.shared-runtime.ts
.../next/src/shared/lib/app-router-context.shared-runtime.ts
+5
-0
adapters.tsx
packages/next/src/shared/lib/router/adapters.tsx
+16
-23
No files found.
packages/next/src/client/components/app-router.tsx
View file @
5740ef3e
...
@@ -391,7 +391,6 @@ function Router({
...
@@ -391,7 +391,6 @@ function Router({
})
})
})
})
},
},
// @ts-ignore we don't want to expose this method at all
fastRefresh
:
()
=>
{
fastRefresh
:
()
=>
{
if
(
process
.
env
.
NODE_ENV
!==
'development'
)
{
if
(
process
.
env
.
NODE_ENV
!==
'development'
)
{
throw
new
Error
(
throw
new
Error
(
...
...
packages/next/src/client/components/react-dev-overlay/app/hot-reloader-client.tsx
View file @
5740ef3e
...
@@ -410,7 +410,6 @@ function processMessage(
...
@@ -410,7 +410,6 @@ function processMessage(
return
window
.
location
.
reload
()
return
window
.
location
.
reload
()
}
}
startTransition
(()
=>
{
startTransition
(()
=>
{
// @ts-ignore it exists, it's just hidden
router
.
fastRefresh
()
router
.
fastRefresh
()
dispatcher
.
onRefresh
()
dispatcher
.
onRefresh
()
})
})
...
@@ -435,17 +434,10 @@ function processMessage(
...
@@ -435,17 +434,10 @@ function processMessage(
reloading
=
true
reloading
=
true
return
window
.
location
.
reload
()
return
window
.
location
.
reload
()
}
}
case
HMR_ACTIONS_SENT_TO_BROWSER
.
ADDED_PAGE
:
case
HMR_ACTIONS_SENT_TO_BROWSER
.
REMOVED_PAGE
:
{
case
HMR_ACTIONS_SENT_TO_BROWSER
.
REMOVED_PAGE
:
{
// TODO-APP: potentially only refresh if the currently viewed page was removed.
// TODO-APP: potentially only refresh if the currently viewed page was added/removed.
// @ts-ignore it exists, it's just hidden
return
router
.
fastRefresh
()
router
.
fastRefresh
()
return
}
case
HMR_ACTIONS_SENT_TO_BROWSER
.
ADDED_PAGE
:
{
// TODO-APP: potentially only refresh if the currently viewed page was added.
// @ts-ignore it exists, it's just hidden
router
.
fastRefresh
()
return
}
}
case
HMR_ACTIONS_SENT_TO_BROWSER
.
SERVER_ERROR
:
{
case
HMR_ACTIONS_SENT_TO_BROWSER
.
SERVER_ERROR
:
{
const
{
errorJSON
}
=
obj
const
{
errorJSON
}
=
obj
...
@@ -476,7 +468,7 @@ export default function HotReload({
...
@@ -476,7 +468,7 @@ export default function HotReload({
errorOverlayReducer
,
errorOverlayReducer
,
INITIAL_OVERLAY_STATE
INITIAL_OVERLAY_STATE
)
)
const
dispatcher
=
useMemo
(():
Dispatcher
=>
{
const
dispatcher
=
useMemo
<
Dispatcher
>
(()
=>
{
return
{
return
{
onBuildOk
()
{
onBuildOk
()
{
dispatch
({
type
:
ACTION_BUILD_OK
})
dispatch
({
type
:
ACTION_BUILD_OK
})
...
@@ -494,7 +486,7 @@ export default function HotReload({
...
@@ -494,7 +486,7 @@ export default function HotReload({
dispatch
({
type
:
ACTION_VERSION_INFO
,
versionInfo
})
dispatch
({
type
:
ACTION_VERSION_INFO
,
versionInfo
})
},
},
}
}
},
[
dispatch
])
},
[])
const
handleOnUnhandledError
=
useCallback
((
error
:
Error
):
void
=>
{
const
handleOnUnhandledError
=
useCallback
((
error
:
Error
):
void
=>
{
const
errorDetails
=
(
error
as
any
).
details
as
const
errorDetails
=
(
error
as
any
).
details
as
...
@@ -533,6 +525,9 @@ export default function HotReload({
...
@@ -533,6 +525,9 @@ export default function HotReload({
const
router
=
useRouter
()
const
router
=
useRouter
()
useEffect
(()
=>
{
useEffect
(()
=>
{
const
websocket
=
webSocketRef
.
current
if
(
!
websocket
)
return
const
handler
=
(
event
:
MessageEvent
<
any
>
)
=>
{
const
handler
=
(
event
:
MessageEvent
<
any
>
)
=>
{
try
{
try
{
const
obj
=
JSON
.
parse
(
event
.
data
)
const
obj
=
JSON
.
parse
(
event
.
data
)
...
@@ -550,12 +545,8 @@ export default function HotReload({
...
@@ -550,12 +545,8 @@ export default function HotReload({
}
}
}
}
const
websocket
=
webSocketRef
.
current
websocket
.
addEventListener
(
'message'
,
handler
)
if
(
websocket
)
{
return
()
=>
websocket
.
removeEventListener
(
'message'
,
handler
)
websocket
.
addEventListener
(
'message'
,
handler
)
}
return
()
=>
websocket
&&
websocket
.
removeEventListener
(
'message'
,
handler
)
},
[
sendMessage
,
router
,
webSocketRef
,
dispatcher
,
processTurbopackMessage
])
},
[
sendMessage
,
router
,
webSocketRef
,
dispatcher
,
processTurbopackMessage
])
return
(
return
(
...
...
packages/next/src/shared/lib/app-router-context.shared-runtime.ts
View file @
5740ef3e
...
@@ -125,6 +125,11 @@ export interface AppRouterInstance {
...
@@ -125,6 +125,11 @@ export interface AppRouterInstance {
* Refresh the current page.
* Refresh the current page.
*/
*/
refresh
():
void
refresh
():
void
/**
* Refresh the current page. Use in development only.
* @internal
*/
fastRefresh
():
void
/**
/**
* Navigate to the provided href.
* Navigate to the provided href.
* Pushes a new history entry.
* Pushes a new history entry.
...
...
packages/next/src/shared/lib/router/adapters.tsx
View file @
5740ef3e
import
type
{
import
type
{
AppRouterInstance
}
from
'../app-router-context.shared-runtime'
AppRouterInstance
,
NavigateOptions
,
}
from
'../app-router-context.shared-runtime'
import
type
{
Params
}
from
'./utils/route-matcher'
import
type
{
Params
}
from
'./utils/route-matcher'
import
type
{
NextRouter
}
from
'./router'
import
type
{
NextRouter
}
from
'./router'
...
@@ -11,33 +8,29 @@ import { isDynamicRoute } from './utils'
...
@@ -11,33 +8,29 @@ import { isDynamicRoute } from './utils'
import
{
asPathToSearchParams
}
from
'./utils/as-path-to-search-params'
import
{
asPathToSearchParams
}
from
'./utils/as-path-to-search-params'
import
{
getRouteRegex
}
from
'./utils/route-regex'
import
{
getRouteRegex
}
from
'./utils/route-regex'
/**
/** It adapts a Pages Router (`NextRouter`) to the App Router Instance. */
* adaptForAppRouterInstance implements the AppRouterInstance with a NextRouter.
*
* @param router the NextRouter to adapt
* @returns an AppRouterInstance
*/
export
function
adaptForAppRouterInstance
(
export
function
adaptForAppRouterInstance
(
r
outer
:
NextRouter
pagesR
outer
:
NextRouter
):
AppRouterInstance
{
):
AppRouterInstance
{
return
{
return
{
back
()
:
void
{
back
()
{
r
outer
.
back
()
pagesR
outer
.
back
()
},
},
forward
()
:
void
{
forward
()
{
r
outer
.
forward
()
pagesR
outer
.
forward
()
},
},
refresh
()
:
void
{
refresh
()
{
r
outer
.
reload
()
pagesR
outer
.
reload
()
},
},
push
(
href
:
string
,
{
scroll
}:
NavigateOptions
=
{}):
void
{
fastRefresh
()
{},
void
router
.
push
(
href
,
undefined
,
{
scroll
})
push
(
href
,
{
scroll
}
=
{})
{
void
pagesRouter
.
push
(
href
,
undefined
,
{
scroll
})
},
},
replace
(
href
:
string
,
{
scroll
}:
NavigateOptions
=
{}):
void
{
replace
(
href
,
{
scroll
}
=
{})
{
void
r
outer
.
replace
(
href
,
undefined
,
{
scroll
})
void
pagesR
outer
.
replace
(
href
,
undefined
,
{
scroll
})
},
},
prefetch
(
href
:
string
):
void
{
prefetch
(
href
)
{
void
r
outer
.
prefetch
(
href
)
void
pagesR
outer
.
prefetch
(
href
)
},
},
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment