diff --git a/samples/react-script-editor/README.md b/samples/react-script-editor/README.md index 4cbb2d017..cb9ea4d55 100644 --- a/samples/react-script-editor/README.md +++ b/samples/react-script-editor/README.md @@ -161,6 +161,7 @@ Version|Date|Comments 1.0.0.13|July 1th, 2019|Downgrade to SPFx v1.4.1 to support SP2019 1.0.0.14|Oct 13th, 2019|Added resolve to fix pnpm issue. Updated author info. 1.0.0.15|Mar 16th, 2020|Upgrade to SPFx v1.10.0. Add support for Teams tab. Renamed package file. +1.0.0.16|April 1st, 2010|Improved how script tags are handled and cleaned up on smart page navigation. ## Disclaimer **THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.** diff --git a/samples/react-script-editor/config/package-solution.json b/samples/react-script-editor/config/package-solution.json index 697a035cb..6c25bcb94 100644 --- a/samples/react-script-editor/config/package-solution.json +++ b/samples/react-script-editor/config/package-solution.json @@ -3,7 +3,7 @@ "solution": { "name": "Modern Script Editor web part by mikaelsvenson", "id": "1425175f-3ed8-44d2-8fc4-dd1497191294", - "version": "1.0.0.15", + "version": "1.0.0.16", "includeClientSideAssets": true, "skipFeatureDeployment": false, "isDomainIsolated": false diff --git a/samples/react-script-editor/src/webparts/scriptEditor/ScriptEditorWebPart.ts b/samples/react-script-editor/src/webparts/scriptEditor/ScriptEditorWebPart.ts index d86676034..5b0679c30 100644 --- a/samples/react-script-editor/src/webparts/scriptEditor/ScriptEditorWebPart.ts +++ b/samples/react-script-editor/src/webparts/scriptEditor/ScriptEditorWebPart.ts @@ -10,6 +10,7 @@ import PropertyPaneLogo from './PropertyPaneLogo'; export default class ScriptEditorWebPart extends BaseClientSideWebPart { public _propertyPaneHelper; + private _unqiueId; constructor() { super(); @@ -22,6 +23,7 @@ export default class ScriptEditorWebPart extends BaseClientSideWebPart 0) { - return; - } - if (elem.onload && elem.onload.length > 0) { - scriptTag.onload = elem.onload; + for (let i = 0; i < elem.attributes.length; i++) { + const attr = elem.attributes[i]; + // Copies all attributes in case of loaded script relies on the tag attributes + if(attr.name.toLowerCase() === "onload" ) continue; // onload handled after loading with SPComponentLoader + scriptTag.setAttribute(attr.name, attr.value); } + // set a bogus type to avoid browser loading the script, as it's loaded with SPComponentLoader + scriptTag.type = (scriptTag.src && scriptTag.src.length) > 0 ? "pnp" : "text/javascript"; + // Ensure proper setting and adding id used in cleanup on reload + scriptTag.setAttribute("pnpname", this._unqiueId); + try { // doesn't work on ie... scriptTag.appendChild(document.createTextNode(data)); @@ -156,7 +162,6 @@ export default class ScriptEditorWebPart extends BaseClientSideWebPartwindow).ScriptGlobal = {}; // main section of function @@ -210,10 +224,10 @@ export default class ScriptEditorWebPart extends BaseClientSideWebPart