Skip to content

Commit

Permalink
Merge pull request #367 from escobar-felipe/feat/deferscript-id
Browse files Browse the repository at this point in the history
feat: add support for setting an id to the dynamically created script…
  • Loading branch information
emilhe authored Dec 17, 2024
2 parents 57c350d + 28cc107 commit 67d0191
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 67d0191

Please sign in to comment.