Unverified Commit b8b653bb authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

Clean up unused code in restart server button (#82409)

parent 1779eb05
import { useEffect } from 'react'
import { RefreshClockWise } from '../../../icons/refresh-clock-wise'
import {
ACTION_RESTART_SERVER_BUTTON,
type OverlayDispatch,
} from '../../../shared'
import type { SupportedErrorEvent } from '../../../container/runtime-error/render-error'
import { useRestartServer } from './use-restart-server'
import { css } from '../../../utils/css'
/**
* When the Turbopack persistent cache is enabled, and the user reloads on a
* specific error and that error persists, we show the restart server button as
* an option. This is because some errors are recoverable by clearing the
* bundler cache, but we want to provide a shortcut to do this and collect
* telemetry on how often this is used.
*/
export function RestartServerButton({ showButton }: { showButton: boolean }) {
const { restartServer, isPending } = useRestartServer()
if (!showButton) {
return null
}
return (
<button
className="restart-dev-server-button"
onClick={() => restartServer({ invalidatePersistentCache: true })}
disabled={isPending}
title="Clears the bundler cache and restarts the dev server. Helpful if you are seeing stale errors or changes are not appearing."
>
<RefreshClockWise
width={14}
height={14}
style={{
animation: isPending
? 'refresh-clock-wise-spin 1s linear infinite'
: undefined,
}}
/>
Reset Bundler Cache
</button>
)
}
/**
* Sets up a beforeunload listener to show the restart server button
* if the developer reloads on a specific error and that error persists with Turbopack + Persistent Cache.
*/
export function usePersistentCacheErrorDetection({
errors,
dispatch,
}: {
errors: readonly SupportedErrorEvent[]
dispatch: OverlayDispatch
}) {
useEffect(() => {
const isTurbopackWithCache =
process.env.__NEXT_BUNDLER?.toUpperCase() === 'TURBOPACK' &&
process.env.__NEXT_BUNDLER_HAS_PERSISTENT_CACHE
// TODO: Is there a better heuristic here?
const firstError = errors[0]?.error
if (isTurbopackWithCache && firstError) {
const errorKey = `__next_error_overlay:${window.location.pathname}:${firstError.message}`
const showRestartServerButton = sessionStorage.getItem(errorKey) === '1'
dispatch({
type: ACTION_RESTART_SERVER_BUTTON,
showRestartServerButton,
})
const handleBeforeUnload = () => {
sessionStorage.setItem(errorKey, '1')
}
window.addEventListener('beforeunload', handleBeforeUnload)
return () => {
window.removeEventListener('beforeunload', handleBeforeUnload)
}
} else {
dispatch({
type: ACTION_RESTART_SERVER_BUTTON,
showRestartServerButton: false,
})
}
}, [errors, dispatch])
}
export const RESTART_SERVER_BUTTON_STYLES = css`
.restart-dev-server-button {
display: flex;
justify-content: center;
align-items: center;
gap: 4px;
margin: 0 12px;
height: var(--size-26);
padding: 6px 8px 6px 6px;
background: var(--color-amber-100);
background-clip: padding-box;
border: 1px solid var(--color-gray-alpha-400);
box-shadow: var(--shadow-small);
border-radius: var(--rounded-full);
color: var(--color-amber-900);
font-size: var(--size-12);
font-weight: 500;
line-height: var(--size-16);
}
.restart-dev-server-button:disabled {
opacity: 0.6;
cursor: not-allowed;
}
@keyframes refresh-clock-wise-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
`
import type { OverlayDispatch, OverlayState } from '../../shared' import type { OverlayState } from '../../shared'
import type { StackFrame } from '../../../shared/stack-frame' import type { StackFrame } from '../../../shared/stack-frame'
import { useMemo, useState, useEffect } from 'react' import { useMemo, useState, useEffect } from 'react'
...@@ -6,7 +6,6 @@ import { ...@@ -6,7 +6,6 @@ import {
getErrorByType, getErrorByType,
type ReadyRuntimeError, type ReadyRuntimeError,
} from '../../utils/get-error-by-type' } from '../../utils/get-error-by-type'
import { usePersistentCacheErrorDetection } from '../../components/errors/error-overlay-toolbar/restart-server-button'
export type SupportedErrorEvent = { export type SupportedErrorEvent = {
id: number id: number
...@@ -22,7 +21,6 @@ type Props = { ...@@ -22,7 +21,6 @@ type Props = {
}) => React.ReactNode }) => React.ReactNode
state: OverlayState state: OverlayState
isAppDir: boolean isAppDir: boolean
dispatch: OverlayDispatch
} }
export const RenderError = (props: Props) => { export const RenderError = (props: Props) => {
...@@ -36,7 +34,7 @@ export const RenderError = (props: Props) => { ...@@ -36,7 +34,7 @@ export const RenderError = (props: Props) => {
} }
} }
const RenderRuntimeError = ({ children, state, isAppDir, dispatch }: Props) => { const RenderRuntimeError = ({ children, state, isAppDir }: Props) => {
const { errors } = state const { errors } = state
const [lookups, setLookups] = useState<{ const [lookups, setLookups] = useState<{
...@@ -65,8 +63,6 @@ const RenderRuntimeError = ({ children, state, isAppDir, dispatch }: Props) => { ...@@ -65,8 +63,6 @@ const RenderRuntimeError = ({ children, state, isAppDir, dispatch }: Props) => {
return [ready, next] return [ready, next]
}, [errors, lookups]) }, [errors, lookups])
usePersistentCacheErrorDetection({ errors, dispatch })
useEffect(() => { useEffect(() => {
if (nextError == null) { if (nextError == null) {
return return
......
...@@ -33,7 +33,7 @@ export function DevOverlay() { ...@@ -33,7 +33,7 @@ export function DevOverlay() {
<ComponentStyles /> <ComponentStyles />
<DarkTheme /> <DarkTheme />
<RenderError state={state} dispatch={dispatch} isAppDir={true}> <RenderError state={state} isAppDir={true}>
{({ runtimeErrors, totalErrorCount }) => { {({ runtimeErrors, totalErrorCount }) => {
return ( return (
<> <>
......
export function RefreshClockWise(props: React.SVGProps<SVGSVGElement>) {
return (
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" {...props}>
<path
d="M4.30969 8.37891H2.38782C2.9805 10.3647 4.82188 11.8124 7.00012 11.8125C8.81977 11.8124 10.4043 10.8024 11.2228 9.30957L11.5382 8.73438L12.6896 9.36523L12.3741 9.94043L12.1681 10.2891C11.0815 11.993 9.17324 13.1249 7.00012 13.125C4.42207 13.1249 2.21747 11.5322 1.3136 9.27734V11.375H0.00109863V7.72266L0.0147705 7.58984C0.0760304 7.29089 0.340278 7.06641 0.657349 7.06641H4.30969V8.37891ZM7.00012 0.875C9.57685 0.875118 11.7819 2.46569 12.6866 4.71875V2.625H13.9991V6.27734C13.9991 6.63974 13.7053 6.93354 13.3429 6.93359H9.68958V5.62109H11.6115C11.0186 3.6356 9.17813 2.18763 7.00012 2.1875C5.17131 2.18757 3.57959 3.20771 2.76477 4.71289L2.45227 5.29004L1.29797 4.66504L1.61047 4.08789C2.64547 2.17605 4.67052 0.875068 7.00012 0.875Z"
fill="#A35200"
/>
</svg>
)
}
...@@ -52,10 +52,6 @@ export interface OverlayState { ...@@ -52,10 +52,6 @@ export interface OverlayState {
readonly staticIndicator: boolean readonly staticIndicator: boolean
readonly showIndicator: boolean readonly showIndicator: boolean
readonly disableDevIndicator: boolean readonly disableDevIndicator: boolean
/** Whether to show the restart server button in the panel UI. Currently
* only used when Turbopack + Persistent Cache is enabled.
*/
readonly showRestartServerButton: boolean
readonly debugInfo: DebugInfo readonly debugInfo: DebugInfo
readonly routerType: 'pages' | 'app' readonly routerType: 'pages' | 'app'
/** This flag is used to handle the Error Overlay state in the "old" overlay. /** This flag is used to handle the Error Overlay state in the "old" overlay.
...@@ -105,7 +101,6 @@ export const ACTION_DEVTOOLS_POSITION = 'devtools-position' ...@@ -105,7 +101,6 @@ export const ACTION_DEVTOOLS_POSITION = 'devtools-position'
export const ACTION_DEVTOOLS_PANEL_POSITION = 'devtools-panel-position' export const ACTION_DEVTOOLS_PANEL_POSITION = 'devtools-panel-position'
export const ACTION_DEVTOOLS_PANEL_SIZE = 'devtools-panel-size' export const ACTION_DEVTOOLS_PANEL_SIZE = 'devtools-panel-size'
export const ACTION_DEVTOOLS_SCALE = 'devtools-scale' export const ACTION_DEVTOOLS_SCALE = 'devtools-scale'
export const ACTION_RESTART_SERVER_BUTTON = 'restart-server-button'
export const ACTION_DEVTOOLS_CONFIG = 'devtools-config' export const ACTION_DEVTOOLS_CONFIG = 'devtools-config'
...@@ -216,11 +211,6 @@ export interface DevToolUpdateRouteStateAction { ...@@ -216,11 +211,6 @@ export interface DevToolUpdateRouteStateAction {
page: string page: string
} }
export interface RestartServerButtonAction {
type: typeof ACTION_RESTART_SERVER_BUTTON
showRestartServerButton: boolean
}
export interface DevToolsConfigAction { export interface DevToolsConfigAction {
type: typeof ACTION_DEVTOOLS_CONFIG type: typeof ACTION_DEVTOOLS_CONFIG
devToolsConfig: DevToolsConfig devToolsConfig: DevToolsConfig
...@@ -248,7 +238,6 @@ export type DispatcherEvent = ...@@ -248,7 +238,6 @@ export type DispatcherEvent =
| DevToolsPanelPositionAction | DevToolsPanelPositionAction
| DevToolsScaleAction | DevToolsScaleAction
| DevToolUpdateRouteStateAction | DevToolUpdateRouteStateAction
| RestartServerButtonAction
| DevIndicatorSetAction | DevIndicatorSetAction
| DevToolsConfigAction | DevToolsConfigAction
...@@ -291,7 +280,6 @@ export const INITIAL_OVERLAY_STATE: Omit< ...@@ -291,7 +280,6 @@ export const INITIAL_OVERLAY_STATE: Omit<
refreshState: { type: 'idle' }, refreshState: { type: 'idle' },
versionInfo: { installed: '0.0.0', staleness: 'unknown' }, versionInfo: { installed: '0.0.0', staleness: 'unknown' },
debugInfo: { devtoolsFrontendUrl: undefined }, debugInfo: { devtoolsFrontendUrl: undefined },
showRestartServerButton: false,
devToolsPosition: 'bottom-left', devToolsPosition: 'bottom-left',
devToolsPanelPosition: { devToolsPanelPosition: {
[STORE_KEY_SHARED_PANEL_LOCATION]: 'bottom-left', [STORE_KEY_SHARED_PANEL_LOCATION]: 'bottom-left',
...@@ -479,12 +467,6 @@ export function useErrorOverlayReducer( ...@@ -479,12 +467,6 @@ export function useErrorOverlayReducer(
case ACTION_DEVTOOL_UPDATE_ROUTE_STATE: { case ACTION_DEVTOOL_UPDATE_ROUTE_STATE: {
return { ...state, page: action.page } return { ...state, page: action.page }
} }
case ACTION_RESTART_SERVER_BUTTON: {
return {
...state,
showRestartServerButton: action.showRestartServerButton,
}
}
case ACTION_DEVTOOLS_CONFIG: { case ACTION_DEVTOOLS_CONFIG: {
const { const {
theme, theme,
......
...@@ -21,7 +21,6 @@ import { ...@@ -21,7 +21,6 @@ import {
ACTION_REFRESH, ACTION_REFRESH,
ACTION_RENDERING_INDICATOR_HIDE, ACTION_RENDERING_INDICATOR_HIDE,
ACTION_RENDERING_INDICATOR_SHOW, ACTION_RENDERING_INDICATOR_SHOW,
ACTION_RESTART_SERVER_BUTTON,
ACTION_STATIC_INDICATOR, ACTION_STATIC_INDICATOR,
ACTION_UNHANDLED_ERROR, ACTION_UNHANDLED_ERROR,
ACTION_UNHANDLED_REJECTION, ACTION_UNHANDLED_REJECTION,
...@@ -82,7 +81,6 @@ export function useStorybookOverlayReducer(initialState?: OverlayState) { ...@@ -82,7 +81,6 @@ export function useStorybookOverlayReducer(initialState?: OverlayState) {
case ACTION_REFRESH: case ACTION_REFRESH:
case ACTION_RENDERING_INDICATOR_HIDE: case ACTION_RENDERING_INDICATOR_HIDE:
case ACTION_RENDERING_INDICATOR_SHOW: case ACTION_RENDERING_INDICATOR_SHOW:
case ACTION_RESTART_SERVER_BUTTON:
case ACTION_STATIC_INDICATOR: case ACTION_STATIC_INDICATOR:
case ACTION_UNHANDLED_ERROR: case ACTION_UNHANDLED_ERROR:
case ACTION_UNHANDLED_REJECTION: case ACTION_UNHANDLED_REJECTION:
......
...@@ -20,7 +20,6 @@ import { DEV_TOOLS_INFO_TURBOPACK_INFO_STYLES } from '../components/errors/dev-t ...@@ -20,7 +20,6 @@ import { DEV_TOOLS_INFO_TURBOPACK_INFO_STYLES } from '../components/errors/dev-t
import { DEV_TOOLS_INFO_ROUTE_INFO_STYLES } from '../components/errors/dev-tools-indicator/dev-tools-info/route-info' import { DEV_TOOLS_INFO_ROUTE_INFO_STYLES } from '../components/errors/dev-tools-indicator/dev-tools-info/route-info'
import { DEV_TOOLS_INFO_USER_PREFERENCES_STYLES } from '../components/errors/dev-tools-indicator/dev-tools-info/user-preferences' import { DEV_TOOLS_INFO_USER_PREFERENCES_STYLES } from '../components/errors/dev-tools-indicator/dev-tools-info/user-preferences'
import { FADER_STYLES } from '../components/fader' import { FADER_STYLES } from '../components/fader'
import { RESTART_SERVER_BUTTON_STYLES } from '../components/errors/error-overlay-toolbar/restart-server-button'
import { CALL_STACK_STYLES } from '../components/call-stack/call-stack' import { CALL_STACK_STYLES } from '../components/call-stack/call-stack'
import { ISSUE_FEEDBACK_BUTTON_STYLES } from '../components/errors/error-overlay-toolbar/issue-feedback-button' import { ISSUE_FEEDBACK_BUTTON_STYLES } from '../components/errors/error-overlay-toolbar/issue-feedback-button'
import { ERROR_CONTENT_SKELETON_STYLES } from '../container/runtime-error/error-content-skeleton' import { ERROR_CONTENT_SKELETON_STYLES } from '../container/runtime-error/error-content-skeleton'
...@@ -47,7 +46,6 @@ export function ComponentStyles() { ...@@ -47,7 +46,6 @@ export function ComponentStyles() {
${containerErrorStyles} ${containerErrorStyles}
${containerRuntimeErrorStyles} ${containerRuntimeErrorStyles}
${versionStaleness} ${versionStaleness}
${RESTART_SERVER_BUTTON_STYLES}
${DEV_TOOLS_INFO_STYLES} ${DEV_TOOLS_INFO_STYLES}
${DEV_TOOLS_INFO_TURBOPACK_INFO_STYLES} ${DEV_TOOLS_INFO_TURBOPACK_INFO_STYLES}
${DEV_TOOLS_INFO_ROUTE_INFO_STYLES} ${DEV_TOOLS_INFO_ROUTE_INFO_STYLES}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment