Skip to content
Proyectos

mistahoward/blazor-why-did-you-render

Ver en GitHub

Acerca de

Inspired by WellSoftware's why-did-you-render for React - Why Did You Render for Blazor.

Desarrollo web y de aplicaciones

Cómo se miden estas cifras

Crecimiento de estrellas medido

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
Recopilando historial

Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.

README.md

Original

Blazor.WhyDidYouRender

ko-fi NuGet License: LGPL v3

This tells you why a Blazor component rendered, and whether it even needed to. It's why-did-you-render for Blazor, and it works on Blazor Server, WebAssembly, static SSR and MAUI Hybrid.

Every render of a tracked component gets one report - a verdict, what changed, and what asked for the render:

▶ [WhyDidYouRender] Counter render #2 necessary (0.1 ms)
    _currentCount changed
    Asked for by: event: IncrementCount
    ┌─────────┬───────┬───────────────┬────────┬───────┬──────┐
    │ (index) │ kind  │ name          │ before │ after │ note │
    ├─────────┼───────┼───────────────┼────────┼───────┼──────┤
    │ 0       │ state │ _currentCount │ 0      │ 1     │      │
    └─────────┴───────┴───────────────┴────────┴───────┴──────┘
    session 1a2b3c4d · Server

The verdict is first render, necessary, avoidable or can't tell. It only calls a render avoidable when it could see everything that might have changed. When it can't, it says so and names what it couldn't see into, instead of guessing.

Install

dotnet add package Blazor.WhyDidYouRender

Set it up

Register it with your services. If you've got a Blazor Web App that uses WebAssembly, do this in both Program.cs files - the server's and the .Client project's:

using Blazor.WhyDidYouRender.Extensions;

builder.Services.AddWhyDidYouRender();

Then have the components you want to watch inherit TrackedComponentBase instead of ComponentBase:

@inherits TrackedComponentBase

Want a whole folder tracked? Put that line in an _Imports.razor. And that's it, that's the whole setup. Open your browser's developer tools and check the console.

Read more

  • Getting started: each hosting model, MAUI Hybrid, components that already inherit some other base class, and turning it off outside development.
  • How it works: what it tracks, how it lands on a verdict, and what it can't see.
  • Configuration: every setting and attribute.
  • What it prints: the browser console, ILogger and OpenTelemetry.
  • OpenTelemetry and Aspire: one call and your render metrics show up in the Aspire dashboard or any OTLP backend.
  • Samples: a Blazor Web App, standalone WebAssembly and MAUI Hybrid, with a page for each thing it reports.

Upgrading from 3.x

4.0 is a rebuild, but for most apps upgrading is pretty much "delete your Initialize... calls" and you're done. The migration guide covers everything else. The 3.x docs still live at v3.3.1.

Contributing

Check out CONTRIBUTING.md.

License

LGPL-3.0-or-later.

Explorar proyectos relacionados

Cargando…