Skip to content

Commit 64d2ca5

Browse files
authored
fix: recent change could cause Stick to loose its parent host (#182)
1 parent 2a53705 commit 64d2ca5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/StickPortal.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function StickPortal(
101101
{children}
102102

103103
{top != null && left != null && (
104-
<PortalContext.Provider value={host.parentNode}>
104+
<PortalContext.Provider value={host.parentNode || defaultRoot}>
105105
{createPortal(
106106
<div
107107
ref={containerRef}
@@ -122,7 +122,11 @@ function StickPortal(
122122
)
123123
}
124124

125-
export const PortalContext = createContext<?Node>(document.body)
125+
invariant(document.body, 'Stick can only be used in a browser environment.')
126+
127+
const defaultRoot = document.body
128+
129+
export const PortalContext = createContext<Node>(defaultRoot)
126130

127131
export default forwardRef<StickPortalPropsT, ?HTMLElement>(StickPortal)
128132

0 commit comments

Comments
 (0)