-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
First time navigation doesn't fire enhancedload or DOMContentLoaded events when page is loaded. #59780
Comments
UPDATE: I made a discovery which makes it appear that my JS in the script tags is not executed at all, it is skipped. This means the event handlers are never registered! You can test this by adding a console.log call inside the script tags outside any event handler/function. |
@htmlsplash thanks for contacting us. Can you try disabling enhanced navigation and see if it works that way?
We believe what's happening here is that the script is being brought in as part of an enhanced navigation request. The recommendation is to use a JS module or an alternative solution like |
@javiercn Disabling enhanced nav fixes the problem, but:
I did look at your recommendation (from MackinnonBuck), and I tried it, but it will not work in my scenario because of timing: To sum it up: My Workaround (that works): Working Example - App.razor `<script src="./Components/Pages/pimarc/FormViewControl.razor.js"></script> <script> FormViewControl_init(); </script>`Observations: Even though this works, the problem is that this script will be included on every page, even though the component for which this script is for is not present on the page. UPDATE: |
Is there an existing issue for this?
Describe the bug
Environment:
.net 9
Blazor Static SSR page
Visual Studio: 17.12.3
When navigating to a page for the first time using a simple hyperlink the wired up event handlers to DOMContentLoaded or enhancedload are not invoked, ie. one of these should run, but neither runs.
To view the event handler trace, you need to open dev tools console.
To reproduce:
Go to this repo: https://github.com/htmlsplash/BlazorWebAppTest
Launch project
Open browser dev console
Select "Nav test 1" option from the left nav.
Check the console to see traces.
The source page of interest for this bug report is: NavTest1.razor
NOTE;
This bug is very tricky to reproduce. If you do observe the traces, select "Home" link, press F5 (while on the home page), then go back and select Nav test 1 option.
UPDATE 1:
Read my update comments below.
Expected Behavior
One of the registered handlers for DOMContentLoaded or enhancedload should be invoked.
Steps To Reproduce
See problem description.
Exceptions (if any)
No response
.NET Version
.net 9
Anything else?
No response
The text was updated successfully, but these errors were encountered: