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.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { useCallback } from "react"
|
||||
|
||||
import type { Dashboard } from "@/components/Dashboard/DashboardView"
|
||||
import {
|
||||
CanvasSurface,
|
||||
@@ -33,6 +35,13 @@ export function PanelSurface({
|
||||
/** Whether the screen this hangs on is touched. Stated by the panel route. */
|
||||
touch?: boolean
|
||||
}) {
|
||||
const hasRail = Boolean(rail)
|
||||
// Stable, so the canvas can keep the tiles it already built when one of the
|
||||
// dashboard's own settings re-renders the route above this.
|
||||
const canvas = useCallback(
|
||||
() => <DashboardView dashboard={dashboard} rail={hasRail} />,
|
||||
[dashboard, hasRail],
|
||||
)
|
||||
return (
|
||||
<div className="relative size-full">
|
||||
{stacked ? (
|
||||
@@ -41,7 +50,7 @@ export function PanelSurface({
|
||||
// The panel's own surface, scaled to fit. No dots: nothing is being
|
||||
// arranged here.
|
||||
<CanvasSurface dashboard={dashboard} rail={rail} touch={touch}>
|
||||
{() => <DashboardView dashboard={dashboard} rail={Boolean(rail)} />}
|
||||
{canvas}
|
||||
</CanvasSurface>
|
||||
)}
|
||||
{/* Outside the canvas, so it needs the look stated for it. */}
|
||||
|
||||
Reference in New Issue
Block a user