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

Fix CSS Hot Reload on iOS device #27812

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

spadapet
Copy link
Contributor

Description of Change

This fixes a bug with:

  • MAUI Blazor Hybrid apps
  • Open in Visual Studio 2022
  • Using Pair to Mac to debug on a Mac
  • Hot reload CSS on iOS Simulator

Hot reloading CSS didn't work because the web view on iOS didn't refresh the CSS since the href didn't change. The CSS link looks like:

  • <link rel="stylesheet" href="app.css" />

And when the CSS file changed, the href was modified by adding an empty string to it. The browser in iOS didn't detect any change in the href (since the change was a no-op) and didn't refresh the CSS. On Windows and Android the browser would still refresh CSS when the href had a no-op change.

My fix is to make a real change to the CSS link's href by appending a query string with a timestamp to it. Now all the browsers refresh the CSS since the timestamp is always unique.

Issues Fixed

Bug 1821555: [XVS][MAUI] CSS Hot reload on iOS Simulator not working

@spadapet spadapet self-assigned this Feb 14, 2025
@Copilot Copilot bot review requested due to automatic review settings February 14, 2025 20:25
@spadapet spadapet requested a review from a team as a code owner February 14, 2025 20:25

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

src/BlazorWebView/src/SharedSource/StaticContentHotReloadManager.cs:32

  • Ensure that there is a test case verifying that the CSS reloads correctly with the new timestamp query string.
allLinkElems.forEach(elem => elem.href = elem.href.split('?')[0] + '?reload_version=' + Date.now());
@spadapet spadapet requested a review from lewing February 14, 2025 22:29
@rmarinho rmarinho added the area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging label Feb 17, 2025
@spadapet spadapet enabled auto-merge February 20, 2025 19:46
@spadapet
Copy link
Contributor Author

Ping for code review: @dotnet/dotnet-maui-blazor-eng

@spadapet spadapet force-pushed the dev/peterspa/HotReloadCssMac branch from a3ea9ff to 16321e5 Compare February 21, 2025 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants