Skip to content

Commit

Permalink
Unserializable data type fix for standalone shell
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Aug 17, 2019
1 parent ce65df7 commit 2935d6a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
29 changes: 29 additions & 0 deletions fixtures/standalone/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/immutable@4.0.0-rc.12/dist/immutable.js"></script>

<!-- Don't use this in production: -->
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
Expand Down Expand Up @@ -255,6 +256,33 @@ <h1>List</h1>
);
}

const set = new Set(['abc', 123]);
const map = new Map([['name', 'Brian'], ['food', 'sushi']]);
const setOfSets = new Set([new Set(['a', 'b', 'c']), new Set([1, 2, 3])]);
const mapOfMaps = new Map([['first', map], ['second', map]]);
const typedArray = Int8Array.from([100, -100, 0]);
const immutable = Immutable.fromJS({
a: [{ hello: 'there' }, 'fixed', true],
b: 123,
c: {
'1': 'xyz',
xyz: 1,
},
});

function UnserializableProps() {
return (
<ChildComponent
map={map}
set={set}
mapOfMaps={mapOfMaps}
setOfSets={setOfSets}
typedArray={typedArray}
immutable={immutable}
/>
);
}

function ChildComponent(props: any) {
return null;
}
Expand All @@ -264,6 +292,7 @@ <h1>List</h1>
<Fragment>
<SimpleValues />
<ObjectProps />
<UnserializableProps />
<CustomObject />
</Fragment>
);
Expand Down
14 changes: 12 additions & 2 deletions src/hydration.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,18 @@ export function fillInPath(
}
}

if (value !== null && data.unserializable.includes(path)) {
upgradeUnserializable(value, value);
if (value !== null && data.unserializable.length > 0) {
const unserializablePath = data.unserializable[0];
let isMatch = unserializablePath.length === path.length;
for (let i = 0; i < path.length; i++) {
if (path[i] !== unserializablePath[i]) {
isMatch = false;
break;
}
}
if (isMatch) {
upgradeUnserializable(value, value);
}
}

setInObject(object, path, value);
Expand Down

0 comments on commit 2935d6a

Please sign in to comment.