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

Support disabling auto-injection of browser refresh JavaScript via launch profile property #44805

Open
DamianEdwards opened this issue Oct 31, 2022 · 5 comments
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) feature-hot-reload This issue is related to the Hot Reload feaature Pillar: Dev Experience triaged

Comments

@DamianEdwards
Copy link
Member

As a result of the problems experienced by some customers in their ASP.NET Core apps when the browser refresh script is auto-injected, as detailed in #32767, I’m proposing that we add a new launch settings/profile property that can be used to disable the automatic injection of the browser refresh script.

The property would be named disableBrowserRefreshScriptInjection and would default to false. Setting this property to true in a launch profile in launchSettings.json would prevent dotnet watch and Visual Studio from injecting the middleware that writes out the browser refresh JavaScript to HTML responses from the app, e.g.:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:50226/",
      "sslPort": 44355
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "disableBrowserRefreshScriptInjection": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "https": {
      "commandName": "Project",
      "launchBrowser": true,
      "disableBrowserRefreshScriptInjection": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:7089;http://localhost:5089"
    }
  }
}

Note that this setting should not disable any other part of the mechanism that enables browser refreshing on Hot Reload, project build, CSS file change, etc., so that the app can manually add the required JavaScript reference manually, e.g.

@* Render the browser reload script *@
@if (Environment.GetEnvironmentVariable("__ASPNETCORE_BROWSER_TOOLS") != null)
{
<script src="/_framework/aspnetcore-browser-refresh.js"></script>
}
@DamianEdwards DamianEdwards added feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) feature-hot-reload This issue is related to the Hot Reload feaature labels Oct 31, 2022
@mkArtakMSFT mkArtakMSFT added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label Oct 31, 2022
@mkArtakMSFT mkArtakMSFT added this to the .NET 8 Planning milestone Oct 31, 2022
@Muchiachio
Copy link
Contributor

This is also needed when using front end frameworks which have their own HMR.
Getting whole page refresh on controller change isn't really necessary and results in lost state.

@jsheely
Copy link

jsheely commented May 8, 2023

I would also add that this should work in mixed environments where you have blazor on the page that you want to hot reload and you have a razor page that you want the server side rendering to reload separately

Currently the script aspnetcore-browser-refresh script explicitly denies this capability.

function aspnetCoreHotReloadApplied() {
    if (window.Blazor) {
      // If this page has any Blazor, don't refresh the browser.
      notifyHotReloadApplied();
    } else {
      location.reload();
    }
  }

@aKzenT
Copy link

aKzenT commented Aug 30, 2023

While not perfect, you can already disable the middleware responsible for injecting the JavaScript by using the ASPNETCORE_HOSTINGSTARTUPEXCLUDEASSEMBLIES environment variable. See: #33068 (comment) .

@mkArtakMSFT mkArtakMSFT added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Oct 6, 2023
@mkArtakMSFT mkArtakMSFT modified the milestones: .NET 8 Planning, Backlog Oct 6, 2023
@ghost
Copy link

ghost commented Oct 6, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@ghost
Copy link

ghost commented Dec 1, 2023

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) feature-hot-reload This issue is related to the Hot Reload feaature Pillar: Dev Experience triaged
Projects
None yet
Development

No branches or pull requests

6 participants