.NET Core 8 Blazor Server site- not loading any Javascript on first access after build

blazor.server.js is failing to do its thing on only the very first run of a built dotnet website. The error actually presents as JSInterop being unable to find the first Javascript file it is trying to execute, and this prevents any other scripts from loading and disables all interactivity on the page.

Just reloading the page makes the error go away- and it doesn’t come back in repeated runs from the IIS Express run button in Visual Studio- but if I kill the process in Task Manager and then do dotnet run again on the command line, it’s back. It is also present when I publish to the test server and run the real IIS- the first person to visit the site will see broken javascript.

What makes this a bigger problem is I am now trying to set up automated testing and Playwright starts up a fresh instance of everything for the tests, so it’s always the “first time,” and so the javascript always doesn’t work.

Oh, the question here (which should already have been implied) is “Why is it doing this and how do I fix it- or if no one knows why it’s doing that, how do I work around it so my tests aren’t affected?”