Skip to content

Commit 9256109

Browse files
ztannereps1lon
andauthored
devtools: couple restart dev server UI with persistent cache flag (#80751)
The goal of this UI is to surface a nudge when we think that the server might be in a bad state due to persistent caching problems. It probably doesn't make sense to show up in any other case. While we work to figure out the best way to nudge it in dev, this couples the behavior behind the persistent caching flag. --------- Co-authored-by: Sebastian "Sebbie" Silbermann <[email protected]>
1 parent 5cbee8a commit 9256109

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

packages/next/src/next-devtools/dev-overlay/components/errors/error-overlay-toolbar/error-overlay-toolbar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export function ErrorOverlayToolbar({
1515
}: ErrorOverlayToolbarProps) {
1616
return (
1717
<span className="error-overlay-toolbar">
18-
<RestartServerButton error={error} />
18+
{process.env.__NEXT_BUNDLER_HAS_PERSISTENT_CACHE && (
19+
<RestartServerButton error={error} />
20+
)}
1921
<CopyStackTraceButton error={error} />
2022
<DocsLinkButton errorMessage={error.message} />
2123
<NodejsInspectorButton

packages/next/src/next-devtools/dev-overlay/components/errors/error-overlay-toolbar/restart-server-button.tsx

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import { useState, useEffect } from 'react'
22
import { RefreshClockWise } from '../../../icons/refresh-clock-wise'
33

44
/**
5-
* When the user reloads on a specific error and that error persists, we show
6-
* the restart server button as an option. This is because some errors are
7-
* recoverable by restarting the server and rebuilding the app.
8-
*
9-
* When Turbopack persistent cache is enabled, it will also clear the bundler
10-
* cache. This improves DX by replacing the need to run `rm -rf .next` manually.
5+
* When the Turbopack persistent cache is enabled, and the user reloads on a
6+
* specific error and that error persists, we show the restart server button as
7+
* an option. This is because some errors are recoverable by clearing the
8+
* bundler cache, but we want to provide a shortcut to do this and collect
9+
* telemetry on how often this is used.
1110
*/
1211
export function RestartServerButton({ error }: { error: Error }) {
1312
const [showButton, setShowButton] = useState(false)
@@ -32,14 +31,8 @@ export function RestartServerButton({ error }: { error: Error }) {
3231
}
3332

3433
function handleClick() {
35-
let endpoint = '/__nextjs_restart_dev'
36-
37-
if (process.env.__NEXT_BUNDLER_HAS_PERSISTENT_CACHE) {
38-
endpoint = '/__nextjs_restart_dev?invalidatePersistentCache'
39-
}
40-
4134
// TODO: Use Client Action for transition indicator when DevTools is isolated.
42-
fetch(endpoint, {
35+
fetch('/__nextjs_restart_dev?invalidatePersistentCache', {
4336
method: 'POST',
4437
}).then(() => {
4538
// TODO: poll server status and reload when the server is back up.
@@ -51,14 +44,10 @@ export function RestartServerButton({ error }: { error: Error }) {
5144
<button
5245
className="restart-dev-server-button"
5346
onClick={handleClick}
54-
title={
55-
process.env.__NEXT_BUNDLER_HAS_PERSISTENT_CACHE
56-
? 'Clears the bundler cache and restarts the dev server. Helpful if you are seeing stale errors or changes are not appearing.'
57-
: 'Restarts the development server without needing to leave the browser.'
58-
}
47+
title="Clears the bundler cache and restarts the dev server. Helpful if you are seeing stale errors or changes are not appearing."
5948
>
6049
<RefreshClockWise width={14} height={14} />
61-
Restart Dev Server
50+
Clear Bundler Cache &amp; Restart
6251
</button>
6352
)
6453
}

0 commit comments

Comments
 (0)