react-email-editor icon indicating copy to clipboard operation
react-email-editor copied to clipboard

isScriptInjected needs the srcipt source validated

Open fantypants opened this issue 4 years ago • 0 comments

I kept encountering errors from line 14 of loadScript:

if (script.src.includes(scriptUrl)) {}

It looks like this error occurs when the script source coming into the email editor has no src attribute, however, has js set inside like so:

<script>
!function(){..}
</script>

These were included automatically from the main web app layout (not the React email editor instance), is this normal behaviour?

I have cloned the repo, ammended the block to read the following:

  scripts.forEach((script) => {
    if(typeof script.src !== undefined && script.src !== null && script.getAttribute('src') !== null && script.getAttribute('src') !== undefined){
      if (script.src.includes(scriptUrl)) {
        injected = true;
      }
    }
  });

Seems to have fixed the issue for me, i believe this may have something to do with being part of a larger app outside of React (Phoenix in this case).

Package details: "react": "^17.0.2", "webpack": "^5.21.0",

fantypants avatar Jun 09 '21 19:06 fantypants