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

[Blazor] Fix hot reload for components with collocated JS files #43199

Merged
merged 7 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ Copyright (c) .NET Foundation. All rights reserved.

<ResolveCoreStaticWebAssetsDependsOn>
$(ResolveCoreStaticWebAssetsDependsOn);
ResolveJSModuleStaticWebAssets;
ResolveJsInitializerModuleStaticWebAssets;
</ResolveCoreStaticWebAssetsDependsOn>

<ResolveCoreStaticWebAssetsDependsOn Condition="'$(UsingMicrosoftNETSdkRazor)' == 'true'">
$(ResolveCoreStaticWebAssetsDependsOn);
ResolveJSModuleStaticWebAssets;
</ResolveCoreStaticWebAssetsDependsOn>

</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -229,7 +233,7 @@ Copyright (c) .NET Foundation. All rights reserved.
>
<Output TaskParameter="ResolvedEndpoints" ItemName="_ResolvedJSBuildModuleEndpoints" />
</ResolveStaticWebAssetEndpointRoutes>

<GenerateJsModuleManifest
Condition="'@(_ExistingBuildJSModules)' != ''"
OutputFile="@(_JsModuleBuildManifestCandidate)"
Expand Down Expand Up @@ -341,7 +345,7 @@ Copyright (c) .NET Foundation. All rights reserved.
>
<Output TaskParameter="ResolvedEndpoints" ItemName="_ResolvedJSPublishModuleEndpoints" />
</ResolveStaticWebAssetEndpointRoutes>

<GenerateJsModuleManifest
Condition="'@(_ExistingPublishJSModules)' != ''"
OutputFile="@(_JsModulePublishManifestCandidate)"
Expand Down
25 changes: 21 additions & 4 deletions test/Microsoft.NET.Sdk.Razor.Tests/ScopedCssIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,32 @@ public void RegeneratingScopedCss_ForProject()

// Make an edit
var scopedCssFile = Path.Combine(ProjectDirectory.TestRoot, "Components", "Pages", "Index.razor.css");
File.WriteAllLines(scopedCssFile, File.ReadAllLines(scopedCssFile).Concat(new[] { "body { background-color: orangered; }" }));
File.WriteAllLines(scopedCssFile, File.ReadAllLines(scopedCssFile).Concat(["body { background-color: orangered; }"]));

build = CreateBuildCommand(ProjectDirectory);
ExecuteCommand(build, "/t:UpdateStaticWebAssetsDesignTime").Should().Pass();

// Verify the generated file contains newly added css
AssertFileContains(bundlePath, "background-color: orangered");

// Verify that CSS edits continue to apply after new JS modules are added to the project
// https://github.com/dotnet/aspnetcore/issues/57599
var collocatedJsFile = Path.Combine(ProjectDirectory.TestRoot, "Components", "Pages", "Index.razor.js");
File.WriteAllLines(collocatedJsFile, ["console.log('Hello, world!');"]);
File.WriteAllLines(scopedCssFile, File.ReadAllLines(scopedCssFile).Concat(["h1 { color: purple; }"]));

build = CreateBuildCommand(ProjectDirectory);
ExecuteCommand(build, "/t:UpdateStaticWebAssetsDesignTime").Should().Pass();

var fileInfo = new FileInfo(bundlePath);
fileInfo.Should().Exist();
// Verify the generated file contains newly added css
fileInfo.ReadAllText().Should().Contain("background-color: orangered");
AssertFileContains(bundlePath, "color: purple");

static void AssertFileContains(string fileName, string content)
{
var fileInfo = new FileInfo(fileName);
fileInfo.Should().Exist();
fileInfo.ReadAllText().Should().Contain(content);
}
}
}

Expand Down