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

Append version tag helper does not work for scoped CSS and blazor.webassembly.js #46798

Closed
1 task done
rogihee opened this issue Feb 22, 2023 · 6 comments
Closed
1 task done
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Status: No Recent Activity

Comments

@rogihee
Copy link
Contributor

rogihee commented Feb 22, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have a hosted WASM app in a razor page. The upgrade from dotnet 6.0 to dotnet 7.0 does not work if you have a cached blazor.webassembly.js file, the app gets stuck in the loading / boot sequence of blazor.

I thought I would use the asp-append-version tag helper to fix this in my Razor page where I host the app:

    <environment include="Development" exclude="Production">
        <script src="_framework/blazor.webassembly.js" autostart="false"></script>
    </environment>
    <environment include="Production" exclude="Development">
        <script src="_framework/blazor.webassembly.js" autostart="false" asp-append-version="true"></script>
    </environment>

After publishing this is rendered to:

<script src="_framework/blazor.webassembly.js" autostart="false"></script>

I expected something like:

<script src="_framework/blazor.webassembly.js?v=K1snUvACThylObaJIb1SuZcesNu0Kx348C9wL3nneWQ" autostart="false"></script>

EDIT:
This also applies to the scoped CSS files generated by the SDK:

<link href="MyApp.styles.css" rel="stylesheet" asp-append-version="true" />

Renders to:
<link href="MyApp.styles.css" rel="stylesheet" />

Possibly related to #44216.

Expected Behavior

I expected something like:

<script src="_framework/blazor.webassembly.js?v=K1snUvACThylObaJIb1SuZcesNu0Kx348C9wL3nneWQ" autostart="false"></script>

Steps To Reproduce

  1. Create a new hosted blazor webassembly project version 6.0
  2. Add the version tag helper for the blazor.webassembly.js as above
  3. Publish the site somewhere, say Azure Web App.
  4. Use Edge or Chrome browser to load the site with caching enabled.
  5. Upgrade the project to 7.0 and publish again
  6. Close the browser and restart at the same site
  7. Observe that the app fails to load, stuck at loading with a console error.

I have to try this with an isolated example, this is basically what happened to us in production.

Exceptions (if any)

No response

.NET Version

9.0

Anything else?

No response

@rogihee rogihee changed the title Append version tag helper does not work for blazor.webassembly.js Append version tag helper does not work for scoped CSS and blazor.webassembly.js Feb 22, 2023
@mkArtakMSFT mkArtakMSFT added area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one labels Feb 22, 2023
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Feb 23, 2023
@mkArtakMSFT
Copy link
Member

Thanks for contacting us. It's not clear how the blazor.webassembly.js file got cached (the older version) on your clients' machines. Can you provide a repro step for making that happen, so that we can possibly suggest a workaround?

Also, maybe you can try to append ?1 to the filename and see if that works.

@mkArtakMSFT mkArtakMSFT added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Feb 23, 2023
@mkArtakMSFT mkArtakMSFT removed this from the Backlog milestone Feb 23, 2023
@ghost
Copy link

ghost commented Feb 23, 2023

Hi @rogihee. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@dotnet dotnet deleted a comment Feb 23, 2023
@rogihee
Copy link
Contributor Author

rogihee commented Feb 24, 2023

@mkArtakMSFT the issue occurs when a client has a 6.0 runtime / blazor.webassembly.js cached in their browser and the website is upgraded to 7.0, then the loading fails in the boot sequence somewhere with a module error. Stuck at loading screen. I have modified the repro steps.

I have a workaround, I created this little version extension:

 private static string _version;

    public static string AppendVersion(this string url)
    {
        if (string.IsNullOrEmpty(_version))
        {
            _version = $"?v={Assembly.GetAssembly(typeof(BaseAsset))?.GetName().Version?.ToString() ?? ""}";
        }
        return $"{url}{_version}";
    }

This uses a verison set globally in the Directory.Build.props, so it is slightly less accurate than a file hash, but will do for my purposes. I use this now in the app.cshtml page:

<script src="@("_framework/blazor.webassembly.js".AppendVersion())"></script>

We'll see if this solves the problem. But this issue confirmed my strong dislike of TagHelpers: it can break without any warning or compile error, and a soft runtime error ("nothing") is a pretty horrible dev/deployment experience. Blazor United FTW!

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Feb 24, 2023
@mkArtakMSFT
Copy link
Member

Thanks for additional details. We'll wait for you to confirm if that really solved the problem or not.

@mkArtakMSFT mkArtakMSFT added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Feb 24, 2023
@ghost
Copy link

ghost commented Feb 24, 2023

Hi @rogihee. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost
Copy link

ghost commented Feb 28, 2023

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed Mar 6, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Apr 5, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Status: No Recent Activity
Projects
None yet
Development

No branches or pull requests

2 participants