Skip to content
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

Allow override of base href during Blazor web assembly startup #55189

Closed
1 task done
milanc opened this issue Apr 18, 2024 · 2 comments
Closed
1 task done

Allow override of base href during Blazor web assembly startup #55189

milanc opened this issue Apr 18, 2024 · 2 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@milanc
Copy link

milanc commented Apr 18, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am trying to use blazor custom elements on the web forms application.
Problem is that in order for the component to work base href has to be set on the page.
Setting the base href messes up the relative navigation and form posts on web forms pages.

Describe the solution you'd like

I would like an option to set the "blazorBase" to be used instead of document.baseURI

Additional context

This is similar request to the one reported here #43191 but for blazor.webassembly.js.
I have a web forms migration POC that seems like acceptable solution to modernize legacy apps and sprinkle some new components to be reused across applications.
Here is the repo where I've modified the blazor.webassembly.js to fix custom elements issue relative to base href.
Essentially anywhere where the code is referencing the document.baseURI I've added this
(document.blazorBase || document.baseURI)
This is one of the location in the actual source


I've also have a tweak to solve the cache issue using the same blazorBase variable in dotnet.js
https://github.com/dotnet/runtime/blob/85e8f688ffaf02743da29adff95e98ebd22a6f53/src/mono/browser/runtime/loader/assetsCache.ts#L166
const relativeBaseHref = (globalThis.document.blazorBase || globalThis.document.baseURI)...

So instead of this hack it would be nice to have something as part of the Blazor startup configuration.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Apr 18, 2024
@mkArtakMSFT
Copy link
Member

Thanks for contacting us.
While this may be a great idea, it is not aligned with our long-term vision to make it part of the framework. For many other ideas which don't belong to the framework we encourage the community to build and ship on their own, contributing to the expanding .NET Ecosystem.

You can learn more about our triage process and how we handle issues by reading our Triage Process writeup.

@mkArtakMSFT mkArtakMSFT closed this as not planned Won't fix, can't repro, duplicate, stale Apr 18, 2024
@milanc
Copy link
Author

milanc commented Apr 19, 2024

@mkArtakMSFT thank you for taking your time reading my initial request, and I hope that few additional lines will not be too annoying.

The migration guidelines provided by Microsoft are suggesting using yarp and gradually moving pages to blazor.
Thing is that does not help with shared UI concerns (popups, notifications, navigation...) which would need to be maintained in two different code bases.
Having blazor custom elements on WebForms pages helps with modernization and reusability of those common components.
The only thing missing is ability to adjust the root for loading framework files.

I am sorry to hear that Microsoft is not interested to apply this simple tweak, to allow better migration experience for so many web forms projects out there.
Code could be similar to this config for blazor server

<script src="~/_framework/blazor.server.js" autostart="false"></script>
<script>
Blazor.start({
       configureSignalR: function (builder) {
            builder.withUrl("/", {
                           });
        }
    });
</script>

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

2 participants