{"version":3,"sources":["../../../../src/next-devtools/shared/react-19-hydration-error.ts"],"sourcesContent":["export const REACT_HYDRATION_ERROR_LINK =\n  'https://react.dev/link/hydration-mismatch'\nexport const NEXTJS_HYDRATION_ERROR_LINK =\n  'https://nextjs.org/docs/messages/react-hydration-error'\n\n/**\n * Only React 19+ contains component stack diff in the error message\n */\nconst errorMessagesWithComponentStackDiff = [\n  /^In HTML, (.+?) cannot be a child of <(.+?)>\\.(.*)\\nThis will cause a hydration error\\.(.*)/,\n  /^In HTML, (.+?) cannot be a descendant of <(.+?)>\\.\\nThis will cause a hydration error\\.(.*)/,\n  /^In HTML, text nodes cannot be a child of <(.+?)>\\.\\nThis will cause a hydration error\\./,\n  /^In HTML, whitespace text nodes cannot be a child of <(.+?)>\\. Make sure you don't have any extra whitespace between tags on each line of your source code\\.\\nThis will cause a hydration error\\./,\n]\n\nexport function isHydrationError(error: Error): boolean {\n  return (\n    isErrorMessageWithComponentStackDiff(error.message) ||\n    /Hydration failed because the server rendered (text|HTML) didn't match the client\\./.test(\n      error.message\n    ) ||\n    /A tree hydrated but some attributes of the server rendered HTML didn't match the client properties./.test(\n      error.message\n    )\n  )\n}\n\nexport function isErrorMessageWithComponentStackDiff(msg: string): boolean {\n  return errorMessagesWithComponentStackDiff.some((regex) => regex.test(msg))\n}\n\nexport function getHydrationErrorStackInfo(error: Error): {\n  message: string | null\n  notes: string | null\n  diff: string | null\n} {\n  const errorMessage = error.message\n  if (isErrorMessageWithComponentStackDiff(errorMessage)) {\n    const [message, diffLog = ''] = errorMessage.split('\\n\\n')\n    const diff = diffLog.trim()\n    return {\n      message: diff === '' ? errorMessage.trim() : message.trim(),\n      diff,\n      notes: null,\n    }\n  }\n\n  const [message, maybeComponentStackDiff] = errorMessage.split(\n    `${REACT_HYDRATION_ERROR_LINK}`\n  )\n  const trimmedMessage = message.trim()\n  // React built-in hydration diff starts with a newline\n  if (\n    maybeComponentStackDiff !== undefined &&\n    maybeComponentStackDiff.length > 1\n  ) {\n    const diffs: string[] = []\n    maybeComponentStackDiff.split('\\n').forEach((line) => {\n      if (line.trim() === '') return\n      if (!line.trim().startsWith('at ')) {\n        diffs.push(line)\n      }\n    })\n\n    const [displayedMessage, ...notes] = trimmedMessage.split('\\n\\n')\n    return {\n      message: displayedMessage,\n      diff: diffs.join('\\n'),\n      notes: notes.join('\\n\\n') || null,\n    }\n  } else {\n    const [displayedMessage, ...notes] = trimmedMessage.split('\\n\\n')\n    return {\n      message: displayedMessage,\n      diff: null,\n      notes: notes.join('\\n\\n'),\n    }\n  }\n}\n"],"names":["REACT_HYDRATION_ERROR_LINK","NEXTJS_HYDRATION_ERROR_LINK","errorMessagesWithComponentStackDiff","isHydrationError","error","isErrorMessageWithComponentStackDiff","message","test","msg","some","regex","getHydrationErrorStackInfo","errorMessage","diffLog","split","diff","trim","notes","maybeComponentStackDiff","trimmedMessage","undefined","length","diffs","forEach","line","startsWith","push","displayedMessage","join"],"mappings":"AAAA,OAAO,MAAMA,6BACX,4CAA2C;AAC7C,OAAO,MAAMC,8BACX,yDAAwD;AAE1D;;CAEC,GACD,MAAMC,sCAAsC;IAC1C;IACA;IACA;IACA;CACD;AAED,OAAO,SAASC,iBAAiBC,KAAY;IAC3C,OACEC,qCAAqCD,MAAME,OAAO,KAClD,qFAAqFC,IAAI,CACvFH,MAAME,OAAO,KAEf,sGAAsGC,IAAI,CACxGH,MAAME,OAAO;AAGnB;AAEA,OAAO,SAASD,qCAAqCG,GAAW;IAC9D,OAAON,oCAAoCO,IAAI,CAAC,CAACC,QAAUA,MAAMH,IAAI,CAACC;AACxE;AAEA,OAAO,SAASG,2BAA2BP,KAAY;IAKrD,MAAMQ,eAAeR,MAAME,OAAO;IAClC,IAAID,qCAAqCO,eAAe;QACtD,MAAM,CAACN,SAASO,UAAU,EAAE,CAAC,GAAGD,aAAaE,KAAK,CAAC;QACnD,MAAMC,OAAOF,QAAQG,IAAI;QACzB,OAAO;YACLV,SAASS,SAAS,KAAKH,aAAaI,IAAI,K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