Skip to content

Commit 0468b72

Browse files
authored
fix(cli-tutor): wrap async resource reducer instead of replacing it (#2478)
the custom reducer used state={} as default, losing fields like errorTimes that createAsyncResourceBundle's auto-generated selectors expect. this caused "can't access property 'slice', resource.errorTimes is undefined" crash when localStorage.debug is set (redux-bundler debug mode evaluates all selectors on startup). follow the same pattern as peers.js: delegate to the original reducer and layer custom actions on top.
1 parent 9db5775 commit 0468b72

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

src/bundles/cli-tutor-mode.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,28 @@ bundle.selectIsCliTutorModalOpen = state => !!state.cliTutorMode.showCliTutorMod
2525

2626
bundle.selectCliOptions = state => state.cliTutorMode.cliOptions
2727

28-
bundle.reducer = (state = {}, action) => {
28+
// Wrap the original reducer (like peers.js does) instead of replacing it.
29+
// The original reducer provides initial state with fields like errorTimes: []
30+
// that auto-generated selectors need. Replacing it with state={} causes
31+
// "can't access property 'slice', resource.errorTimes is undefined" crash
32+
// when localStorage.debug is set (redux-bundler debug mode evaluates all
33+
// selectors on startup).
34+
const asyncResourceReducer = bundle.reducer
35+
36+
bundle.reducer = (state, action) => {
37+
const asyncResult = asyncResourceReducer(state, action)
38+
2939
if (action.type === 'CLI_TUTOR_MODE_TOGGLE') {
30-
return { ...state, isCliTutorModeEnabled: action.payload }
40+
return { ...asyncResult, isCliTutorModeEnabled: action.payload }
3141
}
3242
if (action.type === 'CLI_TUTOR_MODAL_ENABLE') {
33-
return { ...state, showCliTutorModal: action.payload }
43+
return { ...asyncResult, showCliTutorModal: action.payload }
3444
}
3545
if (action.type === 'CLI_OPTIONS') {
36-
return { ...state, cliOptions: action.payload }
46+
return { ...asyncResult, cliOptions: action.payload }
3747
}
3848

39-
return state
49+
return asyncResult
4050
}
4151

4252
bundle.doToggleCliTutorMode = key => ({ dispatch }) => {

0 commit comments

Comments
 (0)