Adding this to my answer above, I managed to solve the issue with React StrictMode. Seems to be related to injecting the script-tag when the App is mounted. StrictMode causes the script-tag to be injected twice, I solved it by adding a ref with the script tag as value indicating whether or not the script already was injected. Don’t know if there is a better solution but it seems to work.
This does NOT solve my initial issue, but still wanted to update.
const [loaded, setLoaded] = useState(false);
const fwScriptElement = useRef(null);
useLayoutEffect(() => {
// To support StrictMode, if the script-element has already been mounted to the DOM, don't do it again.
if (fwScriptElement.current !== null) return;
const script = document.createElement('script');
script.src = '{{{appclient}}}';
script.defer = true;
script.addEventListener('load', () => {
console.log('[in-dev] Nestor app-client script load event fired.');
setLoaded(true);
});
document.head.appendChild(script);
fwScriptElement.current = script;
}, []);