Skip to content

Commit 2eae184

Browse files
committed
Add safety checks to modalStack/currentOpenedModal
1 parent 81a4f13 commit 2eae184

4 files changed

Lines changed: 53 additions & 57 deletions

File tree

packages/components/src/components/common/QuickFeedbackRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export function QuickFeedbackRow(_props: QuickFeedbackRowProps) {
4646
}`,
4747
variables: {
4848
input: {
49-
feedback: feedbackText,
50-
screeName: currentOpenedModal.name,
49+
feedback: feedbackText || '',
50+
screeName: (currentOpenedModal && currentOpenedModal.name) || '',
5151
},
5252
},
5353
},

packages/components/src/components/common/SidebarOrBottomBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export const SidebarOrBottomBar = React.memo(
177177
const small = sizename <= '2-medium'
178178

179179
function isModalOpen(modalName: ModalPayload['name']) {
180-
return !!modalStack && modalStack.some(m => m.name === modalName)
180+
return !!modalStack && modalStack.some(m => m && m.name === modalName)
181181
}
182182

183183
const styles = horizontal ? horizontalStyles : verticalStyles

packages/components/src/components/modals/ModalRenderer.tsx

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export function ModalRenderer(props: ModalRendererProps) {
110110
const currentOpenedModal = useReduxState(selectors.currentOpenedModal)
111111
const previouslyOpenedModal = usePrevious(currentOpenedModal)
112112

113-
const isSettings = !!modalStack.find(m => m.name === 'SETTINGS')
113+
const isSettings = !!modalStack.find(m => m && m.name === 'SETTINGS')
114114
const wasSettings = usePrevious(isSettings)
115115

116116
const closeAllModals = useReduxAction(actions.closeAllModals)
@@ -164,62 +164,58 @@ export function ModalRenderer(props: ModalRendererProps) {
164164
},
165165
)[0]
166166

167-
const modalTransitions = useTransition<ModalPayloadWithIndex, any>(
168-
modalStack,
169-
item => `modal-stack-${item.name}`,
170-
{
171-
reset: false,
172-
config: getDefaultReactSpringAnimationConfig({ precision: 1 }),
173-
immediate,
174-
...(appOrientation === 'portrait'
175-
? {
176-
from: (item: ModalPayloadWithIndex) =>
177-
(item.index === 0 && modalStack.length) ||
178-
(item.index > 0 && !modalStack.length)
179-
? { top: Dimensions.get('window').height, left: 0 }
180-
: { top: 0, left: size },
181-
enter: { top: 0, left: 0 },
182-
update: (item: ModalPayloadWithIndex) =>
183-
modalStack.length > 1 && item.index !== modalStack.length - 1
184-
? { top: 0, left: -50 }
185-
: { top: 0, left: 0 },
186-
leave: (item: ModalPayloadWithIndex) =>
187-
item.index === 0 || !modalStack.length
188-
? { top: Dimensions.get('window').height, left: 0 }
189-
: { top: 0, left: size },
190-
}
191-
: {
192-
from: (item: ModalPayloadWithIndex) =>
193-
(item.index === 0 &&
194-
modalStack.length &&
195-
!previouslyOpenedModal) ||
196-
(item.index > 0 && !modalStack.length)
197-
? { left: -size }
198-
: { left: size },
199-
enter: { left: 0 },
200-
update: (item: ModalPayloadWithIndex) =>
201-
item.index !== modalStack.length - 1
202-
? { left: -size / 3 }
203-
: { left: 0 },
167+
const modalTransitions = useTransition<
168+
ModalPayloadWithIndex | undefined,
169+
any
170+
>(modalStack, item => `modal-stack-${item && item.name}`, {
171+
reset: false,
172+
config: getDefaultReactSpringAnimationConfig({ precision: 1 }),
173+
immediate,
174+
...(appOrientation === 'portrait'
175+
? {
176+
from: (item: ModalPayloadWithIndex) =>
177+
(item.index === 0 && modalStack.length) ||
178+
(item.index > 0 && !modalStack.length)
179+
? { top: Dimensions.get('window').height, left: 0 }
180+
: { top: 0, left: size },
181+
enter: { top: 0, left: 0 },
182+
update: (item: ModalPayloadWithIndex) =>
183+
modalStack.length > 1 && item.index !== modalStack.length - 1
184+
? { top: 0, left: -50 }
185+
: { top: 0, left: 0 },
186+
leave: (item: ModalPayloadWithIndex) =>
187+
item.index === 0 || !modalStack.length
188+
? { top: Dimensions.get('window').height, left: 0 }
189+
: { top: 0, left: size },
190+
}
191+
: {
192+
from: (item: ModalPayloadWithIndex) =>
193+
(item.index === 0 && modalStack.length && !previouslyOpenedModal) ||
194+
(item.index > 0 && !modalStack.length)
195+
? { left: -size }
196+
: { left: size },
197+
enter: { left: 0 },
198+
update: (item: ModalPayloadWithIndex) =>
199+
item.index !== modalStack.length - 1
200+
? { left: -size / 3 }
201+
: { left: 0 },
204202

205-
leave: (item: ModalPayloadWithIndex) =>
206-
item.index >= modalStack.length &&
207-
modalStack.length &&
208-
previouslyOpenedModal &&
209-
previouslyOpenedModal.name === item.name &&
210-
previousModalStack &&
211-
previousModalStack[0] &&
212-
previousModalStack[0].name ===
213-
(modalStack[0] && modalStack[0].name)
214-
? { left: size }
215-
: { left: -size },
216-
}),
217-
},
218-
)
203+
leave: (item: ModalPayloadWithIndex) =>
204+
item.index >= modalStack.length &&
205+
modalStack.length &&
206+
previouslyOpenedModal &&
207+
previouslyOpenedModal.name === item.name &&
208+
previousModalStack &&
209+
previousModalStack[0] &&
210+
previousModalStack[0].name === (modalStack[0] && modalStack[0].name)
211+
? { left: size }
212+
: { left: -size },
213+
}),
214+
})
219215

220216
const separatorTransitions = useTransition<string, any>(
221217
renderSeparator && sizename !== '2-medium' && modalStack.length
222-
? [modalStack[0].name]
218+
? [(modalStack[0] && modalStack[0]!.name) || '']
223219
: [],
224220
item => `modal-separator-${item}`,
225221
{

packages/components/src/redux/reducers/navigation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ModalPayloadWithIndex } from '@devhub/core'
44
import { Reducer } from '../types'
55

66
export interface State {
7-
modalStack: ModalPayloadWithIndex[]
7+
modalStack: Array<ModalPayloadWithIndex | undefined>
88
}
99

1010
const initialState: State = {

0 commit comments

Comments
 (0)