{"version":3,"file":"ViteDevServerStopped.mjs","sources":["../../src/core/studio/ViteDevServerStopped.tsx"],"sourcesContent":["/* eslint-disable i18next/no-literal-string -- will not support i18n in error boundaries */\nimport {Card, Container, Heading, Stack, Text} from '@sanity/ui'\nimport {type ReactNode, useCallback, useEffect, useState} from 'react'\nimport {type ViteHotContext} from 'vite/types/hot.js'\n\nconst ERROR_TITLE = 'Dev server stopped'\nconst ERROR_DESCRIPTION =\n  'The development server has stopped. You may need to restart it to continue working.'\n\nexport class ViteDevServerStoppedError extends Error {\n  ViteDevServerStoppedError: boolean\n\n  constructor() {\n    super(ERROR_TITLE)\n    this.name = 'ViteDevServerStoppedError'\n    this.ViteDevServerStoppedError = true\n  }\n}\nconst serverHot = import.meta.hot\nconst isViteServer = (hot: unknown): hot is ViteHotContext => Boolean(hot)\n\nconst useDetectViteDevServerStopped = () => {\n  const [devServerStopped, setDevServerStopped] = useState(false)\n\n  const markDevServerStopped = useCallback(() => setDevServerStopped(true), [])\n\n  useEffect(() => {\n    // no early return to optimize tree-shaking\n    if (isViteServer(serverHot)) {\n      serverHot.on('vite:ws:disconnect', markDevServerStopped)\n    }\n  }, [markDevServerStopped])\n\n  return {devServerStopped}\n}\n\nconst ThrowViteServerStopped = () => {\n  const {devServerStopped} = useDetectViteDevServerStopped()\n\n  if (devServerStopped) throw new ViteDevServerStoppedError()\n\n  return null\n}\n\nexport const DetectViteDevServerStopped = (): ReactNode =>\n  isViteServer(serverHot) ? <ThrowViteServerStopped /> : null\n\nexport const DevServerStoppedErrorScreen = (): ReactNode => (\n  <Card\n    height=\"fill\"\n    overflow=\"auto\"\n    paddingY={[4, 5, 6, 7]}\n    paddingX={4}\n    sizing=\"border\"\n    tone=\"critical\"\n  >\n    <Container width={3}>\n      <Stack space={4}>\n        <Heading>{ERROR_TITLE}</Heading>\n\n        <Card border radius={2} overflow=\"auto\" padding={4} tone=\"inherit\">\n          <Stack space={4}>\n            <Text size={2}>{ERROR_DESCRIPTION}</Text>\n          </Stack>\n        </Card>\n      </Stack>\n    </Container>\n  </Card>\n)\n"],"names":["ERROR_TITLE","ERROR_DESCRIPTION","ViteDevServerStoppedError","Error","constructor","name","serverHot","import","hot","isViteServer","Boolean","useDetectViteDevServerStopped","$","_c","devServerStopped","setDevServerStopped","useState","t0","Symbol","for","markDevServerStopped","t1","t2","on","useEffect","t3","ThrowViteServerStopped","DetectViteDevServerStopped","DevServerStoppedErrorScreen"],"mappings":";;;;AAKA,MAAMA,cAAc,sBACdC,oBACJ;AAEK,MAAMC,kCAAkCC,MAAM;AAAA,EAGnDC,cAAc;AACZ,UAAMJ,WAAW,GACjB,KAAKK,OAAO,6BACZ,KAAKH,4BAA4B;AAAA,EAAA;AAErC;AACA,MAAMI,YAAYC,YAAYC,KACxBC,eAAgBD,SAAwCE,CAAQF,CAAAA,KAEhEG,gCAAgCA,MAAA;AAAAC,QAAAA,IAAAC,EAAA,CAAA,GACpC,CAAAC,kBAAAC,mBAAA,IAAgDC,WAAc;AAACC,MAAAA;AAAAL,IAAA,CAAA,MAAAM,OAAAC,IAAA,2BAAA,KAEtBF,KAAAA,MAAMF,sBAAwB,GAACH,OAAAK,MAAAA,KAAAL,EAAA,CAAA;AAAxE,QAAAQ,uBAA6BH;AAAgD,MAAAI,IAAAC;AAAAV,IAAA,CAAA,MAAAM,OAAAC,IAAA,2BAAA,KAEnEE,KAAAA,MAAA;AAEJZ,iBAAAH,SAAsB,KACxBA,UAAAiB,GAAa,sBAAsBH,oBAAoB;AAAA,EAAA,GAExDE,MAACF,oBAAoB,GAACR,OAAAS,IAAAT,OAAAU,OAAAD,KAAAT,EAAA,CAAA,GAAAU,KAAAV,EAAA,CAAA,IALzBY,UAAUH,IAKPC,EAAsB;AAACG,MAAAA;AAAA,SAAAb,SAAAE,oBAEnBW,KAAA;AAAA,IAAAX;AAAAA,EAAkBF,GAAAA,OAAAE,kBAAAF,OAAAa,MAAAA,KAAAb,EAAA,CAAA,GAAlBa;AAAkB,GAGrBC,yBAAyBA,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