Skip to content

Commit f715bbe

Browse files
committed
Fix rendering async wrapped components
Fixes #79
1 parent 372e6d7 commit f715bbe

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/utils/nonce.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
const isServer = typeof window === `undefined`;
22

3+
function isAsyncComponentFactory(componentOrFactory) {
4+
return typeof componentOrFactory === `function`;
5+
}
6+
7+
function resolveComponent(componentOrFactory) {
8+
if (isAsyncComponentFactory(componentOrFactory)) {
9+
return componentOrFactory().then(componentModule => componentModule.default);
10+
}
11+
return componentOrFactory;
12+
}
13+
314
export function makeNonce({ component, hydrationPromise }) {
415
if (isServer) return component;
516

6-
return () => hydrationPromise.then(() => component);
17+
return () => hydrationPromise.then(() => resolveComponent(component));
718
}

0 commit comments

Comments
 (0)