Stop a bound dashboard setting rebuilding every tile
A setting driven by a flow re-renders whatever reads it on every message. `LookProvider` and `PaletteProvider` built a fresh context value each time, and `CanvasSurface` called its render prop again, so a value on `theme`, `palette`, `look`, `background`, `touch` or `locked` reconciled the whole widget tree and re-ran every chart's `setData`. The palette is now read as roles once per set of colours, the tokens and both context values are memoised on it, and the canvas holds the tiles it built while the callback and the scale stay put. `WidgetBody` is memoised too: its two props are stable while the document is, so a grid rendered for its own reasons no longer rebuilds every chart with it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VfgHWr7AQDiLsTQVu7hpKB
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { TriangleAlert } from "lucide-react"
|
||||
import { useState } from "react"
|
||||
import { memo, useState } from "react"
|
||||
import { ErrorBoundary } from "react-error-boundary"
|
||||
|
||||
import type { WidgetDef } from "@/client"
|
||||
@@ -749,7 +749,7 @@ const RENDERERS: Partial<
|
||||
color: ColorWidget,
|
||||
}
|
||||
|
||||
export function WidgetBody({ widget, dashboard }: WidgetProps) {
|
||||
function WidgetBodyComponent({ widget, dashboard }: WidgetProps) {
|
||||
const Renderer = RENDERERS[widget.type]
|
||||
if (!Renderer) {
|
||||
return (
|
||||
@@ -769,6 +769,17 @@ export function WidgetBody({ widget, dashboard }: WidgetProps) {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* What a tile draws, held across a render of the grid around it.
|
||||
*
|
||||
* Both props stay put while the document does — a widget keeps its identity,
|
||||
* and the dashboard is a name — so a grid re-rendered for reasons of its own no
|
||||
* longer rebuilds every chart with it. Nothing a tile watches is held back by
|
||||
* the boundary: its bound value, the look and the palette all reach it below
|
||||
* here, through its own subscriptions.
|
||||
*/
|
||||
export const WidgetBody = memo(WidgetBodyComponent)
|
||||
|
||||
function WidgetFailed() {
|
||||
return (
|
||||
<p className="flex h-full items-center justify-center gap-2 text-muted-foreground text-sm">
|
||||
|
||||
Reference in New Issue
Block a user