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.

网站与应用开发

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
0
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

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.

探索相关项目

加载中…