From eecb3830ac697fe673dc229117b9ab1257ba7be9 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Wed, 10 Nov 2021 18:54:41 +0100 Subject: [PATCH 1/2] - Add management of webRootPath arguement for the real file import while using _import_ emulation. webRootPath does nothing on _import_ emulation on IE11 / Edge as it will use the packaged ES5 module - es5Module argument loading will take the document.baseURI URL in consideration while trying to be loaded at startup. --- .../Blazor.Polyfill.Build.csproj | 2 +- .../Blazor.Polyfill.Server.csproj | 2 +- .../dist/fake.polyfill.js | 48 ++++++++++++++++- .../Daddoon.Blazor.Polyfill.JS.csproj | 2 +- src/Daddoon.Blazor.Polyfill.JS/src/Boot.js | 43 ++++++++++++++- .../src/Boot.js.map | 2 +- src/Daddoon.Blazor.Polyfill.JS/src/Boot.ts | 54 ++++++++++++++++++- 7 files changed, 144 insertions(+), 9 deletions(-) diff --git a/src/Blazor.Polyfill.Build/Blazor.Polyfill.Build.csproj b/src/Blazor.Polyfill.Build/Blazor.Polyfill.Build.csproj index 44f0627..98810e3 100644 --- a/src/Blazor.Polyfill.Build/Blazor.Polyfill.Build.csproj +++ b/src/Blazor.Polyfill.Build/Blazor.Polyfill.Build.csproj @@ -72,7 +72,7 @@ - + diff --git a/src/Blazor.Polyfill.Server/Blazor.Polyfill.Server.csproj b/src/Blazor.Polyfill.Server/Blazor.Polyfill.Server.csproj index bab88cd..482ef14 100644 --- a/src/Blazor.Polyfill.Server/Blazor.Polyfill.Server.csproj +++ b/src/Blazor.Polyfill.Server/Blazor.Polyfill.Server.csproj @@ -3,7 +3,7 @@ net6.0 true - 6.0.100.0 + 6.0.100.1 Guillaume ZAHRA Daddoon true diff --git a/src/Blazor.Polyfill.Server/dist/fake.polyfill.js b/src/Blazor.Polyfill.Server/dist/fake.polyfill.js index eb8fae0..8382193 100644 --- a/src/Blazor.Polyfill.Server/dist/fake.polyfill.js +++ b/src/Blazor.Polyfill.Server/dist/fake.polyfill.js @@ -1,4 +1,50 @@ -window._import_ = function (fileName) { +window._import_ = function (fileName, webRootPath) { + + if (webRootPath === undefined || webRootPath === null) { + webRootPath = ""; + } + + function pathJoin(path1, path2) { + + if (path1 === null || path1 === undefined) { + path1 = ""; + } + + if (path2 === null || path2 === undefined) { + path2 = ""; + } + + var needTrail = true; + var path1hasTrail = false; + var path2hasTrail = false; + + if (path1.length - 1 >= 0 && (path1[path1.length - 1] == '/' || path1[path1.length - 1] == '\\')) { + needTrail = false; + path1hasTrail = true; + } + + if (path2.length > 0 && (path2[0] == '/' || path2[0] == '\\')) { + needTrail = false; + path2hasTrail = true; + } + + if (needTrail) { + return path1 + "/" + path2; + } + else { + if (path1hasTrail && path2hasTrail) { + return path1 + path2.substring(1); + } + else if (path1hasTrail && !path2hasTrail) { + return path1 + path2; + } + else if (!path1hasTrail && path2hasTrail) { + return path1 + path2; + } + } + } + + fileName = pathJoin(webRootPath, fileName); if (fileName.length > 0 && fileName[0] !== '/') { console.log("_import_: For compatibility reasons, assuming current path '" + fileName + "' as absolute."); diff --git a/src/Daddoon.Blazor.Polyfill.JS/Daddoon.Blazor.Polyfill.JS.csproj b/src/Daddoon.Blazor.Polyfill.JS/Daddoon.Blazor.Polyfill.JS.csproj index feee211..2de6854 100644 --- a/src/Daddoon.Blazor.Polyfill.JS/Daddoon.Blazor.Polyfill.JS.csproj +++ b/src/Daddoon.Blazor.Polyfill.JS/Daddoon.Blazor.Polyfill.JS.csproj @@ -12,7 +12,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Daddoon.Blazor.Polyfill.JS/src/Boot.js b/src/Daddoon.Blazor.Polyfill.JS/src/Boot.js index 237b2e3..45ae7f2 100644 --- a/src/Daddoon.Blazor.Polyfill.JS/src/Boot.js +++ b/src/Daddoon.Blazor.Polyfill.JS/src/Boot.js @@ -93,6 +93,39 @@ require("get-root-node-polyfill/implement"); } return stack.join("/"); } + function pathJoin(path1, path2) { + if (path1 === null || path1 === undefined) { + path1 = ""; + } + if (path2 === null || path2 === undefined) { + path2 = ""; + } + var needTrail = true; + var path1hasTrail = false; + var path2hasTrail = false; + if (path1.length - 1 >= 0 && (path1[path1.length - 1] == '/' || path1[path1.length - 1] == '\\')) { + needTrail = false; + path1hasTrail = true; + } + if (path2.length > 0 && (path2[0] == '/' || path2[0] == '\\')) { + needTrail = false; + path2hasTrail = true; + } + if (needTrail) { + return path1 + "/" + path2; + } + else { + if (path1hasTrail && path2hasTrail) { + return path1 + path2.substring(1); + } + else if (path1hasTrail && !path2hasTrail) { + return path1 + path2; + } + else if (!path1hasTrail && path2hasTrail) { + return path1 + path2; + } + } + } blazorPolyfill(); //Must be set by prior by the server but sanity checking here if (window._es5ShouldLoadModuleAfterBoot === undefined || window._es5ShouldLoadModuleAfterBoot === null) { @@ -129,16 +162,22 @@ require("get-root-node-polyfill/implement"); return Promise.reject(new Error('es5Export: Cannot find module "' + fileName + '"')); } }; - window._import_ = function (fileName) { + window._import_ = function (fileName, webRootPath) { //Assuming that if this polyfill is loaded the user want a full ES5 compliant //behavior, even with imports. + //Actually webRootPath is only use for the real import version that may not retrieve the right base path when + //trying to load the real isolated file from absolute //The "no polyfill" version does integrate an _import_ that call the native import return window._es5Import(fileName); }; //After this script is finished, we must "inject" the ES5 fallback user lib, if configured from the server if (window._es5ShouldLoadModuleAfterBoot) { var script = document.createElement("script"); - script.src = window._es5modulePath; + //We should compute the script path in adequation of the current app root executing path + //Either done automatically or overidden + var relativeBaseURI = new URL(document.baseURI).pathname; + var absoluteES5ModulePath = pathJoin(relativeBaseURI, window._es5modulePath); + script.src = absoluteES5ModulePath; document.body.appendChild(script); } })(); diff --git a/src/Daddoon.Blazor.Polyfill.JS/src/Boot.js.map b/src/Daddoon.Blazor.Polyfill.JS/src/Boot.js.map index a6cbe5e..c4b28f1 100644 --- a/src/Daddoon.Blazor.Polyfill.JS/src/Boot.js.map +++ b/src/Daddoon.Blazor.Polyfill.JS/src/Boot.js.map @@ -1 +1 @@ -{"version":3,"file":"Boot.js","sourceRoot":"","sources":["Boot.ts"],"names":[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,iCAAiC,GAAG,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC;SACxF;IACL,CAAC,CAAA;IAED,MAAM,CAAC,QAAQ,GAAG,UAAU,QAAQ,EAAE,WAAW;QAC7C,6EAA6E;QAC7E,8BAA8B;QAE9B,6GAA6G;QAC7G,qDAAqD;QAErD,kFAAkF;QAClF,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC,CAAC;IAEF,0GAA0G;IAC1G,IAAI,MAAM,CAAC,6BAA6B,EAAE;QACtC,IAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAEhD,wFAAwF;QACxF,wCAAwC;QAExC,IAAI,eAAe,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC;QACzD,IAAI,qBAAqB,GAAG,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC;QAE7E,MAAM,CAAC,GAAG,GAAG,qBAAqB,CAAC;QACnC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;KACrC;AACL,CAAC,CAAC,EAAE,CAAC"} \ No newline at end of file diff --git a/src/Daddoon.Blazor.Polyfill.JS/src/Boot.ts b/src/Daddoon.Blazor.Polyfill.JS/src/Boot.ts index d15ff72..3a6507c 100644 --- a/src/Daddoon.Blazor.Polyfill.JS/src/Boot.ts +++ b/src/Daddoon.Blazor.Polyfill.JS/src/Boot.ts @@ -119,6 +119,46 @@ declare var File; return stack.join("/"); } + function pathJoin(path1, path2) { + + if (path1 === null || path1 === undefined) { + path1 = ""; + } + + if (path2 === null || path2 === undefined) { + path2 = ""; + } + + var needTrail = true; + var path1hasTrail = false; + var path2hasTrail = false; + + if (path1.length - 1 >= 0 && (path1[path1.length - 1] == '/' || path1[path1.length - 1] == '\\')) { + needTrail = false; + path1hasTrail = true; + } + + if (path2.length > 0 && (path2[0] == '/' || path2[0] == '\\')) { + needTrail = false; + path2hasTrail = true; + } + + if (needTrail) { + return path1 + "/" + path2; + } + else { + if (path1hasTrail && path2hasTrail) { + return path1 + path2.substring(1); + } + else if (path1hasTrail && !path2hasTrail) { + return path1 + path2; + } + else if (!path1hasTrail && path2hasTrail) { + return path1 + path2; + } + } + } + blazorPolyfill(); //Must be set by prior by the server but sanity checking here @@ -166,10 +206,13 @@ declare var File; } } - window._import_ = function (fileName) { + window._import_ = function (fileName, webRootPath) { //Assuming that if this polyfill is loaded the user want a full ES5 compliant //behavior, even with imports. + //Actually webRootPath is only use for the real import version that may not retrieve the right base path when + //trying to load the real isolated file from absolute + //The "no polyfill" version does integrate an _import_ that call the native import return window._es5Import(fileName); }; @@ -177,7 +220,14 @@ declare var File; //After this script is finished, we must "inject" the ES5 fallback user lib, if configured from the server if (window._es5ShouldLoadModuleAfterBoot) { const script = document.createElement("script"); - script.src = window._es5modulePath; + + //We should compute the script path in adequation of the current app root executing path + //Either done automatically or overidden + + var relativeBaseURI = new URL(document.baseURI).pathname; + var absoluteES5ModulePath = pathJoin(relativeBaseURI, window._es5modulePath); + + script.src = absoluteES5ModulePath; document.body.appendChild(script); } })(); From d4a8cfd0d3601e1209ea80c4deb7cf9fab268dac Mon Sep 17 00:00:00 2001 From: Guillaume ZAHRA Date: Sat, 13 Nov 2021 20:18:52 +0100 Subject: [PATCH 2/2] Update README.md --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index d978705..cb2ce05 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,22 @@ Here are the step to install it: var module = await js.InvokeAsync( "_import_", "/js/modules/exampleJsInterop.js"); ``` + + **However** due to some context limitation, the **\_import\_** may fail if the current app root path you are targeting is not a rooted URL. + This mean: + + - This should work by default: https://127.0.0.1/[blazorpage] + - This should not work by default: https://127.0.0.1/myotherapp/managingsomeurl/[blazorpage] + + In order to workaround this limitation, you may have to compute the relative path by yourself in C# before calling \_import\_, and give it in addition, as a second parameter, the webRootPath. + For our second URL example, https://127.0.0.1/myotherapp/managingsomeurl/[blazorpage], this would be instead: + + ```razor + var module = await js.InvokeAsync( + "_import_", "/js/modules/exampleJsInterop.js", "/myotherapp/managingsomeurl/"); + ``` + + You should find some hint with the **NavigationManager.BaseURI** service / property. See the Microsoft documentation for the Blazor API usage.