@samitouri / QOS-React-2 / commits / 2935d6a18d

Unserializable data type fix for standalone shell

Brian Vaughn committed Aug 17, 2019 at 11:31 UTC 2935d6a18d0c10343919891e4245ccec126155e1
2 files changed +41 -2
fixtures/standalone/index.html
+29
@@ -9,6 +9,7 @@
9
10 <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
11 <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
12 + <script src="https://unpkg.com/immutable@4.0.0-rc.12/dist/immutable.js"></script>
13
14 <!-- Don't use this in production: -->
15 <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
@@ -255,6 +256,33 @@
256 );
257 }
258
259 + const set = new Set(['abc', 123]);
260 + const map = new Map([['name', 'Brian'], ['food', 'sushi']]);
261 + const setOfSets = new Set([new Set(['a', 'b', 'c']), new Set([1, 2, 3])]);
262 + const mapOfMaps = new Map([['first', map], ['second', map]]);
263 + const typedArray = Int8Array.from([100, -100, 0]);
264 + const immutable = Immutable.fromJS({
265 + a: [{ hello: 'there' }, 'fixed', true],
266 + b: 123,
267 + c: {
268 + '1': 'xyz',
269 + xyz: 1,
270 + },
271 + });
272 +
273 + function UnserializableProps() {
274 + return (
275 + <ChildComponent
276 + map={map}
277 + set={set}
278 + mapOfMaps={mapOfMaps}
279 + setOfSets={setOfSets}
280 + typedArray={typedArray}
281 + immutable={immutable}
282 + />
283 + );
284 + }
285 +
286 function ChildComponent(props: any) {
287 return null;
288 }
@@ -264,6 +292,7 @@
292 <Fragment>
293 <SimpleValues />
294 <ObjectProps />
295 + <UnserializableProps />
296 <CustomObject />
297 </Fragment>
298 );
src/hydration.js
+12 -2
@@ -362,8 +362,18 @@ export function fillInPath(
362 }
363 }
364
365 - if (value !== null && data.unserializable.includes(path)) {
366 - upgradeUnserializable(value, value);
365 + if (value !== null && data.unserializable.length > 0) {
366 + const unserializablePath = data.unserializable[0];
367 + let isMatch = unserializablePath.length === path.length;
368 + for (let i = 0; i < path.length; i++) {
369 + if (path[i] !== unserializablePath[i]) {
370 + isMatch = false;
371 + break;
372 + }
373 + }
374 + if (isMatch) {
375 + upgradeUnserializable(value, value);
376 + }
377 }
378
379 setInObject(object, path, value);