- From: falsandtru <notifications@github.com>
- Date: Sun, 24 Sep 2017 14:48:29 -0700
- To: w3c/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/webcomponents/issues/669@github.com>
After url and dom are changed by SPA or PJAX, requested scripts must NOT be evaluated. So importing must have failed if url has changed. If it is not a module script, we can cancel the evaluation of that. But if it is a module script, we cannot cancel the evaluation of that. Here is my code having this problem. ```ts const url = new URL(standardizeUrl(location.href)); if (script.type.toLowerCase() === 'module') { return wait.then(() => import(script.src)) .then( () => ( void script.dispatchEvent(new Event('load')), Right(script)), reason => ( void script.dispatchEvent(new Event('error')), Left(new FatalError(reason instanceof Error ? reason.message : reason + '')))); } else { return script.hasAttribute('defer') ? wait.then(evaluate) : evaluate(); } function evaluate() { try { if (new URL(standardizeUrl(location.href)).path !== url.path) throw new FatalError('Expired.'); if (skip.has(standardizeUrl(location.href))) throw new FatalError('Expired.'); void (0, eval)(code); script.hasAttribute('src') && void script.dispatchEvent(new Event('load')); return Right(script); } catch (reason) { script.hasAttribute('src') && void script.dispatchEvent(new Event('error')); return Left(new FatalError(reason instanceof Error ? reason.message : reason + '')); } } ``` https://github.com/falsandtru/pjax-api/blob/ae05475a829974d634b46ac346939a599c90545b/src/layer/domain/router/module/update/script.ts#L123-L152 -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/w3c/webcomponents/issues/669
Received on Sunday, 24 September 2017 21:48:51 UTC