Skip to content

Commit

Permalink
feat: add support for setting an id to the dynamically created script…
Browse files Browse the repository at this point in the history
… element in DeferScript component
  • Loading branch information
escobar-felipe authored Dec 6, 2024
1 parent 57c350d commit 28cc107
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/lib/components/DeferScript.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ import PropTypes from 'prop-types';
export default class DeferScript extends React.Component {

componentDidMount () {
if (this.props.src) {
const { src, id } = this.props;
if (src) {
const {src} = this.props;
const script = document.createElement('script');

script.src = src;
script.defer = true;

if (id) {
script.id = id;
}

document.body.appendChild(script);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/components/defer_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
style={"maxWidth": "100%"},
**{"data-mxgraph": unescape(mxgraph)},
),
DeferScript(src="https://viewer.diagrams.net/js/viewer-static.min.js"),
DeferScript(id="viewer", src="https://viewer.diagrams.net/js/viewer-static.min.js"),
]
)

Expand Down

0 comments on commit 28cc107

Please sign in to comment.