From 28cc107085a9ceb8a991189083a1a83803edb813 Mon Sep 17 00:00:00 2001 From: escobar-felipe <85838376+escobar-felipe@users.noreply.github.com> Date: Thu, 5 Dec 2024 21:05:52 -0300 Subject: [PATCH] feat: add support for setting an id to the dynamically created script element in DeferScript component --- src/lib/components/DeferScript.react.js | 7 ++++++- tests/components/defer_script.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/components/DeferScript.react.js b/src/lib/components/DeferScript.react.js index 67323f2..f6d591b 100644 --- a/src/lib/components/DeferScript.react.js +++ b/src/lib/components/DeferScript.react.js @@ -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); } } diff --git a/tests/components/defer_script.py b/tests/components/defer_script.py index f8f904b..0bb4b2e 100644 --- a/tests/components/defer_script.py +++ b/tests/components/defer_script.py @@ -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"), ] )