Skip to content
프로젝트

mistahoward/blazor-why-did-you-render

GitHub에서 보기

소개

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

웹 및 앱 개발

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

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.

관련 프로젝트 살펴보기

불러오는 중…