{"record":{"id":"6324e30dd9c2ca9b","repo":"mastra-ai/mastra","slug":"sankeychart-must-be-used-within-sankey","errorCode":null,"errorMessage":"SankeyChart must be used within Sankey","messagePattern":"SankeyChart must be used within Sankey","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playground-ui/src/ds/components/SankeyChart/sankey-context.tsx","lineNumber":131,"sourceCode":"      >\n        {children}\n      </SankeyRenderContext.Provider>\n    </SankeyControlsContext.Provider>\n  );\n}\n\n// Context providers and their hooks intentionally share this module.\n// eslint-disable-next-line react-refresh/only-export-components\nexport function useSankey() {\n  const context = useContext(SankeyControlsContext);\n  if (!context) throw new Error('useSankey must be used within Sankey');\n  return context;\n}\n\n// eslint-disable-next-line react-refresh/only-export-components\nexport function useSankeyRenderContext() {\n  const context = useContext(SankeyRenderContext);\n  if (!context) throw new Error('SankeyChart must be used within Sankey');\n  return context;\n}\n\nfunction orderColumns(columns: Array<SankeyChartColumn>, order: Array<string>) {\n  const positions = new Map(order.map((id, index) => [id, index]));\n  return [...columns].sort(\n    (left, right) => (positions.get(left.id) ?? columns.length) - (positions.get(right.id) ?? columns.length),\n  );\n}\n","sourceCodeStart":113,"sourceCodeEnd":141,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/playground-ui/src/ds/components/SankeyChart/sankey-context.tsx#L113-L141","documentation":"useSankeyRenderContext reads SankeyRenderContext, which supplies the computed graph, enabledColumns, hueMap, and fixed-geometry flags used to render the diagram. The context defaults to null and is only populated by <Sankey>, so calling this hook outside a Sankey render tree throws this error. Unlike useSankey (controls), this hook exposes internal render geometry and is only meaningful within the chart.","triggerScenarios":"Invoking useSankeyRenderContext() from a custom node/link renderer, tooltip, or overlay mounted outside <Sankey>; using it in a story/test that renders components in isolation; calling it in a component that renders before Sankey mounts its render context.","commonSituations":"Building custom SVG overlays over the sankey diagram and placing them as siblings rather than children; extracting the chart's tooltip into a separate route; snapshot tests rendering a node component without the chart wrapper.","solutions":["Ensure the consumer is rendered inside the <Sankey> component tree (e.g., via its render props/children API).","Pass graph/columns/hueMap explicitly via props if the component must live outside the chart.","Wrap isolated stories or tests with <Sankey> before rendering consumers of this hook.","Fix conditional rendering so the Sankey provider never unmounts while render-dependent children remain mounted."],"exampleFix":"// before\n<Sankey data={data} />\n<CustomNodeLabel /> {/* useSankeyRenderContext() throws */}\n\n// after\n<Sankey data={data}>\n  <CustomNodeLabel />\n</Sankey>","handlingStrategy":"validation","validationCode":"const render = useContext(SankeyRenderContext);\nif (!render) {\n  // not inside <Sankey>: render placeholder instead of using graph/hueMap\n}","typeGuard":"const hasRenderContext = (v: SankeyRenderContextValue | null): v is SankeyRenderContextValue => v != null;","tryCatchPattern":"try {\n  const render = useSankeyRenderContext();\n  drawOverlay(render.graph, render.hueMap);\n} catch {\n  // outside <Sankey>: skip overlay\n}","preventionTips":["Render node/link/tooltip extensions strictly within the Sankey component tree.","Pass graph/hueMap via props for components that must live outside the chart.","Never mount render-dependent components while <Sankey> is conditionally unmounted.","Include the provider in any isolated test/story setup."],"tags":["react","context","provider-missing","charts"],"backgroundTag":"missing-react-context-provider","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}