1
1
/* global google */
2
2
import invariant from "invariant"
3
+ import canUseDOM from "can-use-dom"
3
4
import React from "react"
4
5
import ReactDOM from "react-dom"
5
6
import PropTypes from "prop-types"
@@ -52,8 +53,23 @@ export class InfoWindow extends React.PureComponent {
52
53
}
53
54
}
54
55
56
+ componentWillMount ( ) {
57
+ if ( ! canUseDOM || this . containerElement ) {
58
+ return
59
+ }
60
+ if ( React . version . match ( / ^ 1 6 / ) ) {
61
+ this . containerElement = document . createElement ( `div` )
62
+ }
63
+ }
64
+
55
65
componentDidMount ( ) {
56
66
componentDidMount ( this , this . state [ INFO_WINDOW ] , eventMap )
67
+ if ( React . version . match ( / ^ 1 6 / ) ) {
68
+ this . state [ INFO_WINDOW ] . setContent ( this . containerElement )
69
+ open ( this . state [ INFO_WINDOW ] , this . context [ ANCHOR ] )
70
+ this . containerElement = undefined
71
+ return
72
+ }
57
73
const content = document . createElement ( `div` )
58
74
ReactDOM . unstable_renderSubtreeIntoContainer (
59
75
this ,
@@ -72,6 +88,9 @@ export class InfoWindow extends React.PureComponent {
72
88
updaterMap ,
73
89
prevProps
74
90
)
91
+ if ( React . version . match ( / ^ 1 6 / ) ) {
92
+ return
93
+ }
75
94
if ( this . props . children !== prevProps . children ) {
76
95
ReactDOM . unstable_renderSubtreeIntoContainer (
77
96
this ,
@@ -85,14 +104,20 @@ export class InfoWindow extends React.PureComponent {
85
104
componentWillUnmount ( this )
86
105
const infoWindow = this . state [ INFO_WINDOW ]
87
106
if ( infoWindow ) {
88
- if ( infoWindow . getContent ( ) ) {
107
+ if ( ! React . version . match ( / ^ 1 6 / ) && infoWindow . getContent ( ) ) {
89
108
ReactDOM . unmountComponentAtNode ( infoWindow . getContent ( ) )
90
109
}
91
110
infoWindow . setMap ( null )
92
111
}
93
112
}
94
113
95
114
render ( ) {
115
+ if ( React . version . match ( / ^ 1 6 / ) ) {
116
+ return ReactDOM . createPortal (
117
+ React . Children . only ( this . props . children ) ,
118
+ this . containerElement
119
+ )
120
+ }
96
121
return false
97
122
}
98
123
}
0 commit comments