forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove redux devtools from router reducer (vercel#70495)
It's a bit odd that we expose this internal debugging capability in production and it seems to cause potential production issues when serializing unsupported data structures ([x-ref ](vercel#69436)) If we feel a need to re-introduce the ability to introspect on the router state even in production we could consider relanding it in an opt-in way, and not run on every action. But I think since we've moved away from throwing promises in reducers (back when the reducers could potentially be replayed by React, in early Suspense implementations), I'm not sure this provides as much value. Fixes vercel#70441
- Loading branch information
Showing
4 changed files
with
39 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 0 additions & 153 deletions
153
packages/next/src/client/components/use-reducer-with-devtools.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { Dispatch } from 'react' | ||
import React, { use } from 'react' | ||
import { useCallback } from 'react' | ||
import type { | ||
AppRouterState, | ||
ReducerActions, | ||
ReducerState, | ||
} from './router-reducer/router-reducer-types' | ||
import type { AppRouterActionQueue } from '../../shared/lib/router/action-queue' | ||
import { isThenable } from '../../shared/lib/is-thenable' | ||
|
||
export function useUnwrapState(state: ReducerState): AppRouterState { | ||
// reducer actions can be async, so sometimes we need to suspend until the state is resolved | ||
if (isThenable(state)) { | ||
const result = use(state) | ||
return result | ||
} | ||
|
||
return state | ||
} | ||
|
||
export function useReducer( | ||
actionQueue: AppRouterActionQueue | ||
): [ReducerState, Dispatch<ReducerActions>] { | ||
const [state, setState] = React.useState<ReducerState>(actionQueue.state) | ||
|
||
const dispatch = useCallback( | ||
(action: ReducerActions) => { | ||
actionQueue.dispatch(action, setState) | ||
}, | ||
[actionQueue] | ||
) | ||
|
||
return [state, dispatch] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters