Skip to content

Commit d72be42

Browse files
committed
Fix typo on suspense error frames
1 parent 1980c56 commit d72be42

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/__tests__/error-boundaries.test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,66 @@ it('guards against infinite render loops', () => {
7777
})
7878
})
7979

80+
it('returns to the next error boundary on a suspense error', () => {
81+
const Inner = jest.fn(() => null)
82+
83+
const Throw = jest.fn(() => {
84+
throw Promise.reject(new Error('Suspense!'))
85+
})
86+
87+
class Outer extends Component {
88+
static getDerivedStateFromProps() {
89+
return { error: false }
90+
}
91+
92+
static getDerivedStateFromError(error) {
93+
expect(error).not.toBeInstanceOf(Promise)
94+
return { error: true }
95+
}
96+
97+
render() {
98+
return this.state.error ? <Inner /> : <Throw />
99+
}
100+
}
101+
102+
const render$ = renderPrepass(<Outer />)
103+
expect(Throw).toHaveBeenCalledTimes(1)
104+
expect(Inner).not.toHaveBeenCalled()
105+
106+
return render$.then(() => {
107+
expect(Inner).toHaveBeenCalledTimes(1)
108+
})
109+
})
110+
111+
it('returns to the next error boundary on a nested error', () => {
112+
const Throw = jest.fn(({ depth }) => {
113+
if (depth >= 4) {
114+
throw new Error('' + depth)
115+
}
116+
117+
return <Throw depth={depth + 1} />
118+
})
119+
120+
class Outer extends Component {
121+
static getDerivedStateFromProps() {
122+
return { error: false }
123+
}
124+
125+
static getDerivedStateFromError(error) {
126+
expect(error.message).toBe('4')
127+
return { error: true }
128+
}
129+
130+
render() {
131+
return !this.state.error ? <Throw depth={1} /> : null
132+
}
133+
}
134+
135+
renderPrepass(<Outer />).then(() => {
136+
expect(Throw).toHaveBeenCalledTimes(4)
137+
})
138+
})
139+
80140
it('always returns to the correct error boundary', () => {
81141
const values = []
82142

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const flushFrames = (queue: Frame[], visitor: Visitor): Promise<void> => {
3838
(error: Error) => {
3939
if (!frame.errorFrame) throw error
4040
frame.errorFrame.error = error
41-
update(frame, queue, visitor)
41+
update(frame.errorFrame, queue, visitor)
4242
}
4343
)
4444
}

0 commit comments

Comments
 (0)