-
Notifications
You must be signed in to change notification settings - Fork 17
routing behaviour on published prerendered wasm project: not loading the prerendered page #24
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
Comments
@dflorean Sorry too late since I was busy watching the .NET Conf 2022 that was held this week. (I live in Japan, so I had to wake up at midnight in the Japan Standard Time zone and keep staying up). By the way, I'm not good at English at all, so it is a bit hard to understand the problem that you reported. |
@jsakamoto hello! yes i know i was following .NET conf too :)
it seems the first time you navigate to a page from the menu is not loaded the blazor page that uses PersistentComponentState but another one trying to reach the API endpoint the main project is [Daniflorex.StaticSpaHost.Backend] the API backend that SHOULD be called only during publish of the frontend (it hosts an instance of Umbraco CMS with sample data) tried to be as clear as possible thanks |
@dflorean Thank you for your kind explanation. I could understand what the problem is. Unfortunately, the behavior that the data are not loaded inter pages navigation after a Blazor Wasm app is loaded on a browser is caused by the design of Blazor. That behavior happens from the structure and architecture of a Blazor Wasm, and from it's the pre-rendering system with states. It is very hard for me to explain in more detail about that with my low English skill, but I believe you can understand eventually after spending time researching by yourself. Fortunately, there is a possibility that we could take some hacks and resolve this issue. This is still a vague idea, so I can't say any specifications of this idea at this time. I'll investigate how to resolve this issue. |
@jsakamoto thank you! I think i might have an idea of what is happening, probably something involved in not loading the entire new page but only some parts of the page (it's still a single page application in the end). |
@jsakamoto i investigated more and understood the problem. The client navigation router is not loading the entire page but only reloading the page component and in that moment the PersistentState is empty cause is designed to persist state when pausing and resuming the app and not during the first load from webassembly.
The last could be a nice solution for your package maybe and a plus feature to have some near to a static generated site/offline experience, but ATM still unable to make it work. i updated the demo site and the repo with these considerations |
I saw someone implemented a NavigationLocker for .NET 6 too, that could be a good solution indeed, i will try. But if u are planning to update the package to 7 this is useless. EDIT: i tried to use the .NET 7 NavigationLock and it creates a loop cause NavigateTo method is itself triggering the onbeforeinternalnavigation event. |
@jsakamoto find the fix, it was stupid: Maybe we could integrate a fix like this in your package (need to update to .NET 7 but i see that added to a .NET 7 wasm app is working). Inject a NavigationLock in the App.razor and handle the OnBeforeInternalNavigation. Maybe configurable like other options for the package. Let me know! |
@jsakamoto i forked and have a look to the project. Could you give me help to the best way to add this feature? i was looking in the BlazorWasmPreRendering.Build.WebHost in the _Layout (where you conditionally add too), but i have problems with multitargeting framework cause this would be only a .NET 7 feature and don't know how to dynamically add the NavigationLock with the event handler |
@dflorean I agree that your approach will be a good solution for your use case. However, your approach will make a Blazor WebAssembly app behave like a traditional Multi Page Application. But most users don't desire such behavior ― make every page navigation cause hard loading ― for the "BlazorWasmPreRendering.Build". The purpose of the "BlazorWasmPreRendering.Build" is not Static Site Generation. The purpose is prerendering for Single Page App. Instead, you can resolve your problem in your app itself, independent of the "BlazorWasmPreRendering.Build". If you want to use Moreover, if your app doesn't have any dynamic user interactions like the "Counter" page, there is no need to hack like you are trying. Just comment out the But I have another idea that might be better than the above options. I'd like to show you my idea, but it will take some time. Please give me a few days. Organize the issue.
Hint: The data persisted to the component state store has been embedded as HTML text in each static prerendered HTML file deployed on the release site web server. |
@jsakamoto sorry you are right, don't worry take your time😊! and thank you for the help! About the hint: yeah i know, i understand that we miss the persisted data HTML of components of other pages in current page and is the reason why the components can't find them and are trying to retrieve from the API endpoints. Probably needing to persist all the prerender data from all the components in the current page when building. |
@dflorean I created a sample project to represent one of the solutions to resolve the problem discussed in this issue thread. https://github.com/sample-by-jsakamoto/Blazor-Reuse-ComponentStates-From-PreRenderedHTML Would you like to check it out? P.S. that is just one of the solutions. I also have other ideas, but another time. |
@jsakamoto very smart approach! Gonna try this out in these days and get a feedback back but i'm for sure liking the solution |
Uh oh!
There was an error while loading. Please reload this page.
Hello! this package is really interesting, sincerely thinking to become a contributor. I want to produce a static prerendered site at PUBLISH/BUILD time with this package, that could be deployed on a static site and no more needs to calls the API layer (blazor actually misses an automatic tool that is doing this, like the feature of Nuxt for VUE for example).
I got the goal using as you mentioned in the documentation the PersistentComponentState service and it is working, but
i'm facing a strange behaviour on routing on hrefs from the navlink menu (but all hrefs are affected): when clicked, it seems the app is trying to load the "non prerendered" page (the one calling the API)" and not the published page the package creates for example in the "fetchdata/index.html". Once you refresh the page the prerendered page is loaded correctly and you can see is totally static and prerendered tryng to refresh it few times in the fetchdata, the data is always the same cause is loaded from the PersistentComponentState. You can reproduce and see this behaviour at this link.
https://staticspademo.z13.web.core.windows.net/
Am i missing something in the routing behaviour that i'm doing wrong?
The text was updated successfully, but these errors were encountered: