Skip to content

Commit

Permalink
fix(compiler): handle null window.location.origin (#2813)
Browse files Browse the repository at this point in the history
when using a data URI or file URI (#2582),
or when using iframe's `srcdoc`, the value for window.location.origin can be `null`.
in these particular cases, passing `null` to `new URL(url, null)` will throw the 
following error: "Failed to construct 'URL': Invalid base URL"
  • Loading branch information
brunor97 authored Jun 23, 2022
1 parent 4656dce commit 255cd66
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/compiler/output-targets/dist-lazy/generate-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ const getSystemLoader = async (
var resourcesUrl = scriptElm ? scriptElm.getAttribute('data-resources-url') || scriptElm.src : '';
var start = function() {
var url = new URL('${corePath}', new URL(resourcesUrl, window.location.origin));
// if src is not present then origin is "null", and new URL() throws TypeError: Failed to construct 'URL': Invalid base URL
var url = new URL('${corePath}', new URL(resourcesUrl, window.location.origin !== 'null' ? window.location.origin : undefined));
System.import(url.href);
};
Expand Down

0 comments on commit 255cd66

Please sign in to comment.