{"record":{"id":"42bd1d020f580caf","repo":"windmill-labs/windmill","slug":"invalid-subgrid-selected-the-parent-has-no-subgri","errorCode":null,"errorMessage":"Invalid subgrid selected, the parent has no subgrids: ${key}, parent: ${JSON.stringify(parent)}","messagePattern":"Invalid subgrid selected, the parent has no subgrids: (.+?), parent: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/lib/components/apps/editor/appUtils.ts","lineNumber":573,"sourceCode":"\t\tapp.subgrids = {}\n\t}\n\n\t// We only want to set subgrids when we are not moving\n\tif (!keepId || keepSubgrids) {\n\t\tfor (let i = 0; i < (data.numberOfSubgrids ?? 0); i++) {\n\t\t\tapp.subgrids[`${id}-${i}`] = []\n\t\t}\n\t}\n\n\tconst key = focusedGrid\n\t\t? `${focusedGrid?.parentComponentId}-${focusedGrid?.subGridIndex ?? 0}`\n\t\t: undefined\n\n\tif (key && app.subgrids[key] === undefined) {\n\t\tlet parent = findGridItemById(app.grid, app.subgrids, key)?.data\n\t\tlet subgrids = parent?.numberOfSubgrids\n\t\tif (subgrids === undefined) {\n\t\t\tthrow Error(\n\t\t\t\t`Invalid subgrid selected, the parent has no subgrids: ${key}, parent: ${JSON.stringify(\n\t\t\t\t\tparent\n\t\t\t\t)}`\n\t\t\t)\n\t\t}\n\t\tif (\n\t\t\tfocusedGrid?.subGridIndex &&\n\t\t\t(focusedGrid?.subGridIndex < 0 || focusedGrid?.subGridIndex >= subgrids)\n\t\t) {\n\t\t\tthrow Error(`Invalid subgrid selected: ${key}, max subgrids: ${subgrids}`)\n\t\t}\n\t\t// If ever the subgrid is undefined, we want to make sure it is defined\n\t\tapp.subgrids[key] = []\n\t}\n\n\tlet grid = focusedGrid ? app.subgrids[key!] : app.grid\n\n\tconst newItem = createNewGridItem(","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/lib/components/apps/editor/appUtils.ts#L555-L591","documentation":"Windmill's app editor throws this when a component is inserted into a subgrid identified by `key`, but the parent grid item stored in `app.grid`/`app.subgrids` cannot be found or has no `numberOfSubgrids` defined. It is a data-integrity guard in `insertNewGridItem` (frontend/src/lib/components/apps/editor/appUtils.ts) ensuring subgrid keys referenced in `app.subgrids` always point to a real parent component that declares subgrids.","triggerScenarios":"Calling insertNewGridItem (directly or via newItem, setUpTopBarComponentContent, handlePaste, moveComponentBetweenSubgrids, moveToRoot) with a `key` where `app.subgrids[key] === undefined` AND `findGridItemById(app.grid, app.subgrids, key)?.data.numberOfSubgrids` is undefined — i.e. the key refers to a deleted/renamed component, or a component that is not a grid-with-subgrids container.","commonSituations":"Pasting a copied component whose focusedGrid key references a container that was deleted; app JSON edited by hand or by a stale script referencing an old component id; moving a component into a subgrid of a plain (non-container) component; race where the parent component was removed between selection and insertion.","solutions":["Re-select the target container in the editor so `focusedGrid.key` points to an existing component with numberOfSubgrids > 0 before inserting","Check that the component id used as subgrid key still exists in app.grid (it may have been deleted or its id changed)","If migrating/patching app JSON, regenerate subgrid keys from the current grid tree instead of reusing stale ones","Wrap programmatic insertions in a guard that calls findGridItemById and checks numberOfSubgrids !== undefined first"],"exampleFix":"// before\nawait insertNewGridItem(app, 'stale-component-id', ...)\n// after\nconst parent = findGridItemById(app.grid, app.subgrids, key)\nif (parent?.data?.numberOfSubgrids !== undefined) {\n  await insertNewGridItem(app, key, ...)\n}","handlingStrategy":"validation","validationCode":"import { findGridItemById } from '$lib/components/apps/editor/appUtils'\nfunction canInsertIntoSubgrid(app, key) {\n  if (!key || app.subgrids[key] !== undefined) return true\n  const parent = findGridItemById(app.grid, app.subgrids, key)\n  return parent?.data?.numberOfSubgrids !== undefined\n}","typeGuard":"function isSubgridParent(item): item is GridItem & { data: { numberOfSubgrids: number } } {\n  return typeof item?.data?.numberOfSubgrids === 'number'\n}","tryCatchPattern":"try {\n  insertNewGridItem(app, key, item)\n} catch (e) {\n  if (String(e.message).startsWith('Invalid subgrid selected')) {\n    toast.error('Target container no longer exists; select a valid grid container')\n  } else throw e\n}","preventionTips":["Always resolve the key via findGridItemById and check numberOfSubgrids before inserting","Delete child subgrid references when removing a container component","Avoid hand-editing app JSON; use the editor so subgrid keys stay in sync","Regenerate subgrid keys when copy/pasting components across apps"],"tags":["app-editor","subgrids","state-corruption"],"backgroundTag":"invalid-subgrid-parent","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}