Open epetersoni opened 2 weeks ago
Add references to [...] scripts in
App.razor
.
Our docs say to include the script in _Layout.cshtml
which to my understanding is the top-level layout page where the <body>
/ <head>
tags are defined by default. Do you have the timing issue if the nimble script tags are included in the _Layout.cshtml
file instead of in App.razor
as described in the docs?
Some other ideas on top of moving the script loading to _Layout.cshtml
:
<script src="_content/NimbleBlazor/nimble-components/all-components-bundle.min.js"></script>
, note it does not have type=module
, or defer
/ async
specified.The default Blazor project templates have seen some significant updates with the last couple .NET releases. I believe _Layout.cshtml
was the default place with <body>
/ <head>
tags for the .NET 6 Blazor project templates. For our actual Armstrong code, we're still based off of the .NET 7 template, which doesn't have _Layout.cshtml
and uses Pages/_Host.cshtml
instead.
With the .NET 8 template, which is what I used for the reproducing example, those tags have moved into App.razor
and there is no longer a .cshtml
file included.
I'm not sure what has changed, but today I've been unable to reproduce using the above steps to reproduce. But it still does reproduce in our full application.
I'll try moving the Nimble script first in our full app and see if that helps.
With the Nimble script moved first in our full app, I've been unable to reproduce this after dozens of attempts. With the Blazor script moved back in front, I can reproduce within a few attempts.
So that appears to be a fix, and I don't notice any other differences in behavior. @rajsite Do you think that's the correct fix, or is there something else I should try?
With the Nimble script moved first in our full app, I've been unable to reproduce this after dozens of attempts. With the Blazor script moved back in front, I can reproduce within a few attempts.
So that appears to be a fix, and I don't notice any other differences in behavior. @rajsite Do you think that's the correct fix, or is there something else I should try?
@epetersoni, could you provide some more clarity around what specific scripts you are arranging? When you say "Nimble script" are you referring to the workaround script (I presume not, as I think we've realized that this isn't relevant), or the all-components script? Presuming the latter case, it's not clear why your changes would be correcting the problem, but we don't believe it should be problematic either.
The larger concern, which I think @rajsite can expand on if needed, is whether or not there is an underlying issue (or expectation) that Microsoft has introduced for how scripts are loaded in a Blazor app. The working theory is that no scripts would attempt to be executed until after window.onload
finishes.
@atmgrifter00 It is the latter case - I moved the all-components script to before the Blazor server script.
Some of our end-to-end tests which were already slightly intermittent started to fail much more frequently around the time of this change, but I'm not clear on how that might be related.
π Bug Report
I have a Blazor component containing a
NimbleDialog
that we want to have open when the component first renders. Intermittently (maybe 30% of the time), I get this JavaScript error about not finding theshow
function:π» Repro or Code Sample
I created a simple reproducing example as follows:
_content/NimbleBlazor/nimble-components/all-components-bundle.min.js
and_content/Radzen.Blazor/Radzen.Blazor.js
scripts inApp.razor
.Home.razor
with<NimbleBlazor.NimbleDialog TCloseReason="string" @ref="_dialog"> Dialog content </NimbleBlazor.NimbleDialog>
@code { private NimbleDialog _dialog = null!;
}