Skip to content

Commit

Permalink
Prevent Excessive Redraws (#4)
Browse files Browse the repository at this point in the history
Only render the diagram if the definition changed.
This commit also adds a class for easier styling/formatting.
  • Loading branch information
DotJoshJohnson authored Jul 7, 2021
1 parent 6099bc0 commit 0981623
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/MermaidJS.Blazor/MermaidDiagram.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@inject MermaidDiagramInterop _interop

<div id="@Id"></div>
<div id="@Id" class="mermaidjs-blazor-diagram"></div>
@if (!string.IsNullOrWhiteSpace(errorMessage))
{
<p style="color:red;">@errorMessage</p>
Expand Down Expand Up @@ -32,6 +32,8 @@
[Parameter]
public EventCallback OnRender { get; set; }

string previousDefinition = string.Empty;

public async ValueTask DisposeAsync()
{
await _interop.UnregisterComponent(this);
Expand Down Expand Up @@ -89,11 +91,13 @@

protected override async Task OnParametersSetAsync()
{
if (componentRef is null)
if (componentRef is null || Definition.Equals(previousDefinition))
{
return;
}

previousDefinition = Definition;

await BeginRender();
}
}

0 comments on commit 0981623

Please sign in to comment.