sanity
Version:
Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches
1 lines • 4.4 kB
Source Map (JSON)
{"version":3,"file":"ViteDevServerStopped.mjs","sources":["../../src/core/studio/ViteDevServerStopped.tsx"],"sourcesContent":["import {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":";;;;AAIA,MAAMA,cAAc,sBACdC,oBACJ;AAEK,MAAMC,kCAAkCC,MAAM;AAAA,EAGnDC,cAAc;AACZ,UAAMJ,WAAW,GACjB,KAAKK,OAAO,6BACZ,KAAKH,4BAA4B;AAAA,EACnC;AACF;AACA,MAAMI,YAAYC,YAAYC,KACxBC,eAAgBD,SAAwCE,CAAAA,CAAQF,KAEhEG,gCAAgCA,MAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA,GACpC,CAAAC,kBAAAC,mBAAA,IAAgDC,WAAc;AAAC,MAAAC;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,EAAC,GAEzDE,MAACF,oBAAoB,GAACR,OAAAS,IAAAT,OAAAU,OAAAD,KAAAT,EAAA,CAAA,GAAAU,KAAAV,EAAA,CAAA,IALzBY,UAAUH,IAKPC,EAAsB;AAAC,MAAAG;AAAA,SAAAb,SAAAE,oBAEnBW,KAAA;AAAA,IAAAX;AAAAA,EAAAA,GAAkBF,OAAAE,kBAAAF,OAAAa,MAAAA,KAAAb,EAAA,CAAA,GAAlBa;AAAk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