fix: plugin script error halting JS execution (#1801)

This commit is contained in:
Marvin Hagemeister
2023-09-20 12:28:32 +02:00
committed by GitHub
parent 0c37b5f9b9
commit 3db514f869
8 changed files with 127 additions and 2 deletions
+7 -1
View File
@@ -91,9 +91,15 @@ export function renderFreshTags(
// Then it imports all plugin scripts and executes them (with their respective
// state).
if (pluginScripts.length > 0) {
// Use `reportError` if available, otherwise throw in a different event
// loop tick to avoid halting the current script.
script +=
`function runPlugin(fn,args){try{fn(args)}catch(err){setTimeout(() => {throw err})}}`;
}
for (const [pluginName, entrypoint, i] of pluginScripts) {
const url = addImport(`plugin-${pluginName}-${entrypoint}.js`);
script += `import p${i} from "${url}";p${i}(STATE[1][${i}]);`;
script += `import p${i} from "${url}";runPlugin(p${i},STATE[1][${i}]);`;
}
// Finally, it loads all island scripts and hydrates the islands using the