@@ -133,67 +133,25 @@ object Builder {
133
133
134
134
val build : BuildFn = {
135
135
136
- val unoptimised : BuildFn =
137
- (tag, props, key, children) => {
138
- key.foreach(setObjectKeyValue(props, " key" , _))
139
- raw.React .createElement(tag, props, children.toSeq: _* )
140
- }
141
-
142
- if (developmentMode)
143
-
144
- // Development mode
145
- unoptimised
146
-
147
- else {
148
- // Production mode
149
- // https://babeljs.io/docs/plugins/transform-react-inline-elements/
150
- // Taken from Babel @ 960fa66c9ef013e247311144332756cdfc9d51bc
151
-
152
- // To check for new changes:
153
- // before=960fa66c9ef013e247311144332756cdfc9d51bc
154
- // after=master
155
- // git diff -M -w -b $before..$after -- packages/babel-helpers/src/helpers.js
156
- // git diff -M -w -b $before..$after -- packages/babel-plugin-transform-react-inline-elements/test/fixtures/inline-elements
157
-
158
- val REACT_ELEMENT_TYPE : js.Any =
159
- try
160
- js.Dynamic .global.Symbol .`for`(" react.element" )
161
- catch {
162
- case _ : Throwable => 0xeac7
163
- }
164
-
165
- (tag, props, key, children) => {
166
-
167
- // From packages/babel-plugin-transform-react-inline-elements/test/fixtures/inline-elements/ref-deopt
168
- val ref = props.asInstanceOf [js.Dynamic ].ref.asInstanceOf [js.UndefOr [js.Any ]]
169
- if (ref.isDefined)
170
- unoptimised(tag, props, key, children)
171
-
172
- else {
173
- // From packages/babel-helpers/src/helpers.js # jsx()
174
-
175
- val clen = children.length
176
- if (clen != 0 ) {
177
- val c = if (clen == 1 ) children(0 ) else children
178
- setObjectKeyValue(props, " children" , c.asInstanceOf [js.Any ])
179
- }
180
-
181
- val output =
182
- js.Dynamic .literal(
183
- `$$typeof` = REACT_ELEMENT_TYPE ,
184
- `type` = tag,
185
- key = key.fold(null : js.Any )(" " + _),
186
- ref = null ,
187
- props = props,
188
- _owner = null )
189
- .asInstanceOf [raw.React .Element ]
190
-
191
- // org.scalajs.dom.console.log("VDOM: ", output)
192
-
193
- output
194
- }
195
- }
136
+ // This used to copy what Babel's transform-react-inline-elements plugin does, but I found a case that broke
137
+ // that I couldn't fix. As a result, it's all gone. We now have the slightly slower, but safer, uniform method
138
+ // that's used in both fastOptJS and fullOptJS.
139
+
140
+ // The issue: (top-level) <Main><div><A/><B/><C/></div></Main>
141
+ // I would continually get this warning: Each child in a list should have a unique "key" prop.
142
+ // There were no array children, keys aren't needed. What really makes this weird and let to me giving up is that
143
+ // if you keep the optimised code as is, but then just call
144
+ // raw.React.createElement(tag, js.Object(), children.toSeq: _*)
145
+ // and throw away the result, the warning would disappear (!). There seems to be some mutation going on somewhere
146
+ // that I can't find. I've inspected all the data I've got access to, looked through React code itself; I can't
147
+ // find where this mutation is occurring. If it's this hard to track down, I don't want scalajs-react being
148
+ // brittle. I don't want it to break when React upgrade their internals. Frustratedly, in to the bin it all goes.
149
+
150
+ (tag, props, key, children) => {
151
+ key.foreach(setObjectKeyValue(props, " key" , _))
152
+ raw.React .createElement(tag, props, children.toSeq: _* )
196
153
}
154
+
197
155
}
198
156
}
199
157
}
0 commit comments