Skip to content

Commit b3c0e7a

Browse files
author
Joe
committed
refactor: improve type-safety in src/server/pure
1 parent 17b66df commit b3c0e7a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/server/pure.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function createServerRenderer<TProps, TResult>(
1313
) {
1414
let renderProps: TProps | undefined
1515
let container: HTMLDivElement | undefined
16-
let serverOutput: string = ''
16+
let serverOutput = ''
1717
const testHarness = createTestHarness(rendererProps, wrapper, false)
1818

1919
return {
@@ -34,7 +34,7 @@ function createServerRenderer<TProps, TResult>(
3434
container = document.createElement('div')
3535
container.innerHTML = serverOutput
3636
act(() => {
37-
ReactDOM.hydrate(testHarness(renderProps), container!)
37+
ReactDOM.hydrate(testHarness(renderProps), container || null)
3838
})
3939
}
4040
},
@@ -43,13 +43,15 @@ function createServerRenderer<TProps, TResult>(
4343
throw new Error('You must hydrate the component before you can rerender')
4444
}
4545
act(() => {
46-
ReactDOM.render(testHarness(props), container!)
46+
ReactDOM.render(testHarness(props), container || null)
4747
})
4848
},
4949
unmount() {
5050
if (container) {
5151
act(() => {
52-
ReactDOM.unmountComponentAtNode(container!)
52+
if (typeof container !== 'undefined') {
53+
ReactDOM.unmountComponentAtNode(container)
54+
}
5355
})
5456
}
5557
},

0 commit comments

Comments
 (0)