-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
There was a problem hiding this comment.
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());
Ping for code review: @dotnet/dotnet-maui-blazor-eng |
16321e5
to
6ad7a2e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there ever a case where the css would have a query string already?
Also, this looks to be getting all css, what happens with CDNs and things like that? Will that refresh all remote ones too?
Good questions. For the CSS files that can be hot reloaded, those are static files and shouldn't have a query string. But your second comment about refreshing all CSS files (even remote ones) is right. That isn't a new problem introduced by this PR, but it was there and I'm touching that code, so I'll see if the refresh can somehow be scoped to what actually changed. |
Ah, @mattleibow looks like refreshing every CSS file was done on purpose: So I think I either:
|
Doesn't the browser have a something to update query strings? Like, if the param exists, then update else add? Edit let url = new URL("https://example.com?foo=1&bar=2");
let params = new URLSearchParams(url.search);
// Add a third parameter.
params.set("baz", 3);
params.toString(); // "foo=1&bar=2&baz=3" |
Yes, I'm about to push my changes that seem to solve the issues:
|
6ad7a2e
to
8f32093
Compare
3c40b3e
to
e34f0a3
Compare
e34f0a3
to
c7f25a8
Compare
* Fix CSS file reloading on Mac * Code review
* Fix CSS file reloading on Mac * Code review
Description of Change
This fixes a bug with:
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