Skip to content
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 @@ -54,7 +54,13 @@ public override Stream Read()

public bool Equals(SourceGeneratorProjectItem? other)
{
if (ReferenceEquals(AdditionalText, other?.AdditionalText))
if (other is null ||
CssScope != other.CssScope)
{
return false;
}

if (ReferenceEquals(AdditionalText, other.AdditionalText))
{
return true;
}
Expand All @@ -64,7 +70,7 @@ public bool Equals(SourceGeneratorProjectItem? other)
// It's technically possible for these hashes to collide, but other things would
// also break in those cases, so for now we're okay with this.
var thisHash = AdditionalText.GetText()?.GetContentHash() ?? [];
var otherHash = other?.AdditionalText.GetText()?.GetContentHash() ?? [];
var otherHash = other.AdditionalText.GetText()?.GetContentHash() ?? [];
return thisHash.SequenceEqual(otherHash);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,38 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) {}
}
}

[Fact]
public async Task IncrementalCompilation_RazorFiles_CssScopeRemoved()
{
// Compile with CssScope set.
var project = CreateTestProject(new()
{
["Pages/Index.razor"] = "<h1>Hello world</h1>",
});
var compilation = await project.GetCompilationAsync();
var (driver, _, options) = await GetDriverWithAdditionalTextAndProviderAsync(project, static options =>
{
options.AdditionalTextOptions["Pages/Index.razor"]["build_metadata.AdditionalFiles.CssScope"] = "test-css-scope";
});

var result = RunGenerator(compilation!, ref driver);
result.Diagnostics.Verify();

// CSS isolation is enabled.
Assert.Contains("<h1 test-css-scope>Hello world</h1>", result.GeneratedSources.Single().SourceText.ToString());

// Unset CssScope.
options = options.Clone();
options.AdditionalTextOptions["Pages/Index.razor"].Options.Remove("build_metadata.AdditionalFiles.CssScope");
driver = driver.WithUpdatedAnalyzerConfigOptions(options);

result = RunGenerator(compilation!, ref driver);
result.Diagnostics.Verify();

// CSS isolation is disabled.
Assert.Contains("<h1>Hello world</h1>", result.GeneratedSources.Single().SourceText.ToString());
}

[Fact]
public async Task SourceGenerator_CshtmlFiles_Works()
{
Expand Down