Skip to content

Fix a couple of issues with dotnet-watch #17608

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

Merged
merged 1 commit into from
May 13, 2021
Merged

Fix a couple of issues with dotnet-watch #17608

merged 1 commit into from
May 13, 2021

Conversation

pranavkm
Copy link
Contributor

  • Print compilation errors in red and don't say hot reload succeeded when there's errors
  • Fix an issue where the browser does not refresh after changes
  • Fix an issue where deltas are not applied on assemblies loaded after the fact.
  • Fix an issue where hot reload no longer works after an app restart.
  • Fix a local dev issue to avoid using the local SDK when running dotnet-watch as an executable

* Print compilation errors in red and don't say hot reload succeeded when there's errors
* Fix an issue where the browser does not refresh after changes
* Fix an issue where deltas are not applied on assemblies loaded after the fact.
* Fix an issue where hot reload no longer works after an app restart.
* Fix a local dev issue to avoid using the local SDK when running dotnet-watch as an executable
@ghost
Copy link

ghost commented May 13, 2021

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@pranavkm pranavkm requested a review from captainsafia May 13, 2021 17:16
@@ -196,6 +196,10 @@ public void ApplyDeltas(IReadOnlyList<UpdateDelta> deltas)
{
System.Reflection.Metadata.AssemblyExtensions.ApplyUpdate(assembly, item.MetadataDelta, item.ILDelta, ReadOnlySpan<byte>.Empty);
}

// Additionally stash the deltas away so it may be applied to assemblies loaded later.
var cachedDeltas = _deltas.GetOrAdd(item.ModuleId, static _ => new());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We were applying these deltas, but I missed storing them.

@@ -53,11 +53,6 @@ public static async Task ReceiveDeltas(HotReloadAgent hotReloadAgent)
Log("Attempting to apply deltas.");

hotReloadAgent.ApplyDeltas(update.Deltas);

// We want to base this off of mvids, but we'll figure that out eventually.
var applyResult = update.ChangedFile is string changedFile && changedFile.EndsWith(".razor", StringComparison.Ordinal) ?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the heuristic about when we refresh the browser in web apps - we won't it if it looks like a Blazor app (presence of any .razor file). Works better than relying on individual files.

@@ -171,7 +179,7 @@ private ImmutableArray<string> GetDiagnostics(Solution solution, CancellationTok
if (item.Severity == DiagnosticSeverity.Error)
{
var diagnostic = CSharpDiagnosticFormatter.Instance.Format(item);
_reporter.Output(diagnostic);
_reporter.Output("\x1B[40m\x1B[31m" + diagnostic);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pretty red color

#if DEBUG
// In the usual case, use the SDK that contains the dotnet-watch. However during local testing, it's
// much more common to run dotnet-watch from a different SDK. Use the ambient SDK in that case.
MSBuildLocator.RegisterDefaults();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Annoying local build issue where it would use the dogfood SDK. This was causing the annoying FailFast error that I poked you about.

{
if (_pipe is not null)
Copy link
Member

Choose a reason for hiding this comment

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

Why was this removed? It seems like good hygiene to have it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out we were newing up these instances in every hot reload loop. So this was never true. Also why the named pipe name is a static because we were only configuring it once.

@pranavkm pranavkm merged commit 9d377b2 into main May 13, 2021
@akoeplinger akoeplinger deleted the prkrishn/bug-fixes branch June 18, 2021 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants