-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Customize the BasePath #46
Comments
Hi @EilifAkerjordet,
Could you tell me the exact names of the script files that failed to load? Providing a screenshot or text of the "network" tab of the browser's dev tools window would be better. Moreover, if you could provide me with a project that reproduces the problem on my side, it might be possible to resolve it faster. Honestly, the most important thing is that I don't understand precisely what you are doing. Thank you for your cooperation. |
@jsakamoto, thanks for looking into this! I appreciate it a lot. :-) Locally/as a normal Blazor WASM app everything works perfectly. It's only when running it on the WP server that I run into issues with the BasePath. Here is a repo with steps to reproduce. Note that it includes a Here the network tab: |
I am very new to .NET. But just looking through the repo a bit and noticing this file: Line 7 in 754155f
Could it be enough just to allow customizing the |
Directly editing the
|
Hi @EilifAkerjordet, I'll keep trying to find a better way and legal solution. In the meantime, I believe your workaround, such as directly editing the |
Hi @EilifAkerjordet, // initialize-blazor.js
(() => {
const basePluginPath = '/wp-content/plugins/akapluss-benefit-search-entrance/';
let restoreOriginalBaseElement = null;
const ensureBaseElementWithPluginPath = () => {
return (() => {
// Just in case, check if the base element is already present in the head element.
const existsBase = document.querySelector('head base') !== null;
if (existsBase) return () => { };
// When the base element is absent, we must add it to the head element
// to ensure that relative URLs are resolved correctly when loading resources.
const base = document.createElement('base');
base.href = basePluginPath;
document.head.appendChild(base);
return () => { document.head.removeChild(base); }
})();
}
Blazor.start({
loadBootResource: (type, name, defaultUri, integrity) => {
// Revert the changes made to the head element made during previous resource loading.
restoreOriginalBaseElement?.();
restoreOriginalBaseElement = null;
// Before loading the 'blazor.boot.json' file, we ensure that the base element
// with the correct base plugin path is in the head element.
// This is necessary to ensure that relative URLs are resolved correctly
// when loading JavaScript initializers.
if (name === "blazor.boot.json") {
restoreOriginalBaseElement = ensureBaseElementWithPluginPath();
}
return `${basePluginPath}_framework/${name}`;
},
});
})(); The root cause of your reported issue is that the base URL is not explicitly specified in the HTML pages that WordPress produces. Blazor's importing JavaScript initializer process strongly depends on the `document.baseURI" to resolve the path of JavaScript initializer script files, so it crashes with an unstabilized base URL. So, as you can see above, I couldn't resolve the issue without a hack that sets up the I hope this answer resolves the problem on your side, too. |
First of all, thank you for spending time on this. This in conjunction with directly modifying the EDIT: |
Hi, love the library, it has helped me a lot!
I have used it to hack together some Blazor WordPress-plugins. Locally it runs fine. I am running into issues however when running it on the WordPress server, as scripts are requested through
{currentUrl}/_content/xxx
instead of{domain}/wp-content/plugins/my-app/_content/xxx
Before hooking on this library this was easily solved by implementing a custom Blazor.start:
Is there a way to achieve the same here?
The text was updated successfully, but these errors were encountered: