Skip to content

Commit e0eebd3

Browse files
committed
fix: use dangerouslySetInnerHTML to ensure everything renders properly
1 parent 06fbd58 commit e0eebd3

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

dist/JSONLD.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ var JSONLD = function JSONLD(props) {
3434
var firstChild = new ChildClass(props.children.props).getJSON(true, schema);
3535
json = ChildClass.name === 'JSONLDNodeCollection' ? _extends({ '@context': 'http://schema.org/' }, _defineProperty({}, type, firstChild)) : _extends({ '@context': 'http://schema.org/' }, firstChild);
3636
}
37-
return _react2.default.createElement(
38-
'script',
39-
{ type: 'application/ld+json' },
40-
JSON.stringify(json)
41-
);
37+
return _react2.default.createElement('script', {
38+
type: 'application/ld+json',
39+
dangerouslySetInnerHTML: {
40+
__html: JSON.stringify(json)
41+
}
42+
});
4243
};
4344

4445
exports.JSONLD = JSONLD;

dist/schemas/Generic.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ var _JSONLDAbstractNode3 = _interopRequireDefault(_JSONLDAbstractNode2);
1616

1717
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1818

19-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
20-
2119
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
2220

2321
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -45,7 +43,8 @@ var ChildNode = function (_JSONLDAbstractNode) {
4543
var details = {
4644
'@type': this.props.jsonldtype
4745
};
48-
return isFirstChildNode ? _extends.apply(undefined, [_extends({}, details, schema)].concat(_toConsumableArray(parseChildren))) : _extends(_defineProperty({}, this.props.id, _extends({}, details, schema, parseChildren)));
46+
47+
return _extends.apply(undefined, [_extends({}, details, schema)].concat(_toConsumableArray(parseChildren)));
4948
}
5049
}]);
5150

src/core/JSONLD.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ export const JSONLD = props => {
1212
: Object.assign({'@context': 'http://schema.org/'}, firstChild)
1313
}
1414
return (
15-
<script type="application/ld+json">{ JSON.stringify(json) }</script>
15+
<script
16+
type="application/ld+json"
17+
dangerouslySetInnerHTML={{
18+
__html: JSON.stringify(json),
19+
}}
20+
/>
1621
);
1722
}
1823

0 commit comments

Comments
 (0)