Skip to content

Commit eb7d5d2

Browse files
committed
Prevent accidental inheritance of previous context on undefined context
1 parent 7583c40 commit eb7d5d2

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/app/services/pageContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export function useUrlPageTheme(): PageContextState {
163163
dispatch(pageContextSlice.actions.updatePageContext({
164164
subject: urlContext?.subject,
165165
stage: urlContext?.stage,
166+
previousContext: {subject: urlContext?.subject, stage: urlContext?.stage},
166167
}));
167168

168169
return () => {

src/app/state/slices/context.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ export const pageContextSlice = createSlice({
1212
reducers: {
1313
updatePageContext: (state, action: actionType) => ({
1414
...state,
15-
stage: action.payload?.stage ?? state?.stage,
16-
subject: action.payload?.subject ?? state?.subject,
15+
// stage and subject can be undefined, so should not ??-inherit from the previous context
16+
stage: action.payload?.stage,
17+
subject: action.payload?.subject,
1718
previousContext: action.payload?.previousContext ?? state?.previousContext,
1819
}),
1920
resetPageContext: (state) => ({

0 commit comments

Comments
 (0)