Skip to content

Commit ce08e58

Browse files
committed
refactor: improve type-safety in src/server/pure
1 parent 25d9521 commit ce08e58

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 {
@@ -33,7 +33,7 @@ function createServerRenderer<TProps, TResult>(
3333
} else {
3434
container.innerHTML = serverOutput
3535
act(() => {
36-
ReactDOM.hydrate(testHarness(renderProps), container!)
36+
ReactDOM.hydrate(testHarness(renderProps), container || null)
3737
})
3838
}
3939
},
@@ -42,13 +42,15 @@ function createServerRenderer<TProps, TResult>(
4242
throw new Error('You must hydrate the component before you can rerender')
4343
}
4444
act(() => {
45-
ReactDOM.render(testHarness(props), container!)
45+
ReactDOM.render(testHarness(props), container || null)
4646
})
4747
},
4848
unmount() {
4949
if (container) {
5050
act(() => {
51-
ReactDOM.unmountComponentAtNode(container!)
51+
if (typeof container !== 'undefined') {
52+
ReactDOM.unmountComponentAtNode(container)
53+
}
5254
})
5355
}
5456
},

0 commit comments

Comments
 (0)