{"record":{"id":"2cc9c4089908f896","repo":"TanStack/query","slug":"the-usage-in-file-filepath-at-line-start","errorCode":null,"errorMessage":"The usage in file \"${filePath}\" at line ${start}:${end} already contains a \"placeholderData\" property. Please migrate this usage manually.","messagePattern":"The usage in file \"(.+?)\" at line (.+?):(.+?) already contains a \"placeholderData\" property\\. Please migrate this usage manually\\.","errorType":"exception","errorClass":"AlreadyHasPlaceholderDataProperty","httpStatus":null,"severity":"warning","filePath":"packages/query-codemods/src/v5/keep-previous-data/keep-previous-data.cjs","lineNumber":102,"sourceCode":"  const getKeepPreviousDataProperty = (objectExpression) => {\n    return objectExpression.properties.find(isKeepPreviousDataObjectProperty)\n  }\n\n  let shouldAddKeepPreviousDataImport = false\n\n  const replacer = (path, resolveTargetArgument, transformNode) => {\n    const node = path.node\n    const { start, end } = getNodeLocation(node)\n\n    try {\n      const targetArgument = resolveTargetArgument(node)\n\n      if (targetArgument && utils.isObjectExpression(targetArgument)) {\n        const isPlaceholderDataPropertyPresent =\n          hasPlaceholderDataProperty(targetArgument)\n\n        if (hasPlaceholderDataProperty(targetArgument)) {\n          throw new AlreadyHasPlaceholderDataProperty(node, filePath)\n        }\n\n        const keepPreviousDataProperty =\n          getKeepPreviousDataProperty(targetArgument)\n\n        const keepPreviousDataPropertyHasTrueValue =\n          isObjectPropertyHasTrueBooleanLiteralValue(keepPreviousDataProperty)\n\n        if (!keepPreviousDataPropertyHasTrueValue) {\n          utils.warn(\n            `The usage in file \"${filePath}\" at line ${start}:${end} already contains a \"keepPreviousData\" property but its value is not \"true\". Please migrate this usage manually.`,\n          )\n\n          return node\n        }\n\n        if (keepPreviousDataPropertyHasTrueValue) {\n          // Removing the `keepPreviousData` property from the object.","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/TanStack/query/blob/159982c80b844487054155c38ffc760fe4208daf/packages/query-codemods/src/v5/keep-previous-data/keep-previous-data.cjs#L84-L120","documentation":"`AlreadyHasPlaceholderDataProperty` thrown by the v5 `keep-previous-data` codemod. The transform converts `keepPreviousData: true` into `placeholderData: keepPreviousData`, but if the target options object already has a `placeholderData` property, overwriting it would silently change behavior, so the codemod refuses and asks for manual migration.","triggerScenarios":"A v4 query that uses BOTH `keepPreviousData: true` AND `placeholderData: ...`; running the `keep-previous-data` codemod on such a call site.","commonSituations":"Codebases that combined both options in v4 to layer placeholder behavior; partial migration where `placeholderData` was already added; copied examples that included both flags.","solutions":["Inspect the cited file:line and decide which placeholder behavior you want in v5.","Manually replace `keepPreviousData: true` with `placeholderData: keepPreviousData` (imported from `@tanstack/react-query`) and remove the conflicting `placeholderData` value, OR keep your existing `placeholderData` and remove `keepPreviousData`.","Re-run the codemod to transform the remaining call sites.","Add a regression test verifying the placeholder behavior after migration."],"exampleFix":"// before\nuseQuery({ queryKey, queryFn, keepPreviousData: true, placeholderData: oldValue })\n// after (manual)\nimport { keepPreviousData } from '@tanstack/react-query'\nuseQuery({ queryKey, queryFn, placeholderData: keepPreviousData })","handlingStrategy":"try-catch","validationCode":"// Detect pre-existing placeholderData before running the codemod.\nfunction hasPlaceholderDataProp(objectExpr: any): boolean {\n  return objectExpr.properties.some((p: any) => p.key?.name === 'placeholderData')\n}","typeGuard":null,"tryCatchPattern":"try { runKeepPreviousDataCodemod(file) } catch (e) { if (e.name === 'AlreadyHasPlaceholderDataProperty') manualQueue.push({ file, loc: e.message }) }","preventionTips":["Audit queries that use both `keepPreviousData` and `placeholderData` before running the codemod.","Decide the desired v5 placeholder behavior in advance.","Run the codemod per-file and review the cited line ranges.","Add a regression test covering placeholder behavior post-migration."],"tags":["codemod","v5-migration","placeholder-data","manual-migration","keep-previous-data"],"backgroundTag":null,"analyzedSha":"159982c80b844487054155c38ffc760fe4208daf","analyzedAt":"2026-08-12T16:21:52.822Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}