{"record":{"id":"138880b9cd834faa","repo":"mermaid-js/mermaid","slug":"configuration-is-required-in-layout-data","errorCode":null,"errorMessage":"Configuration is required in layout data","messagePattern":"Configuration is required in layout data","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid-layout-tidy-tree/src/layout.ts","lineNumber":641,"sourceCode":"      sourceHeight: sourceNode?.height,\n      targetWidth: targetNode?.width,\n      targetHeight: targetNode?.height,\n    };\n  });\n}\n\n/**\n * Validate layout data structure\n * @param data - The data to validate\n * @returns True if data is valid, throws error otherwise\n */\nexport function validateLayoutData(data: LayoutData): boolean {\n  if (!data) {\n    throw new Error('Layout data is required');\n  }\n\n  if (!data.config) {\n    throw new Error('Configuration is required in layout data');\n  }\n\n  if (!Array.isArray(data.nodes)) {\n    throw new Error('Nodes array is required in layout data');\n  }\n\n  if (!Array.isArray(data.edges)) {\n    throw new Error('Edges array is required in layout data');\n  }\n\n  return true;\n}\n","sourceCodeStart":623,"sourceCodeEnd":654,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid-layout-tidy-tree/src/layout.ts#L623-L654","documentation":"Thrown by validateLayoutData when data is truthy but data.config is falsy. The tidy-tree layout expects a Mermaid configuration block inside LayoutData, and its absence indicates the object was constructed incompletely (e.g. copied from a graph that never carried config).","triggerScenarios":"Calling validateLayoutData({nodes:[...], edges:[...]}) with no config field; passing a partial LayoutData built from node/edge arrays only.","commonSituations":"LayoutData assembled manually from extracted nodes/edges without forwarding the original diagram config, or a config-stripping step upstream removed the field.","solutions":["Always attach a config object (typically mermaidApi.getConfig() or the originating diagram's config).","Spread the source LayoutData so config propagates: {...partial, config: getConfig()}.","Default to an empty config object {} if the layout genuinely needs no options."],"exampleFix":"// before\nvalidateLayoutData({ nodes, edges });\n\n// after\nvalidateLayoutData({ nodes, edges, config: getConfig() });","handlingStrategy":"validation","validationCode":"const safe = { ...data, config: data?.config ?? getConfig() };\nvalidateLayoutData(safe);","typeGuard":"function hasConfig(data: unknown): data is { config: object } {\n  return !!data && typeof (data as any).config === 'object' && (data as any).config !== null;\n}","tryCatchPattern":null,"preventionTips":["Always spread config through when copying LayoutData.","Assert data.config is set in producer unit tests."],"tags":["layout","validation","config"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}