UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

1 lines • 3.53 kB
{"version":3,"file":"routeModuleHmrPlugin.js","names":[],"sources":["esm/vite/plugins/routeModuleHmrPlugin.js"],"sourcesContent":["import path from \"node:path\";\nimport { isPathInsideDirectory } from \"../../utils/routeFileWatch\";\nfunction createRouteModuleHmrPlugin(routerRoot) {\n return {\n name: \"route-module-hmr-fix\",\n // the router swallows a failed route import and renders an empty component\n // in its place (see useViteRoutes resolve). that is right for production and\n // wrong for dev, where it meant a broken import anywhere in a route's module\n // graph produced a blank app, no terminal output, and one console line — with\n // every provider inside that route silently never mounting. the client paints\n // its own overlay (devtools/dev.mjs) and reports here so the failure also\n // reaches the terminal, where the person running the dev server is looking.\n configureServer(server) {\n server.hot.on(\n \"one:route-error\",\n (data) => {\n const id = data?.id || \"unknown route\";\n const message = data?.message || \"unknown error\";\n server.config.logger.error(\n `[one] route failed to load: ${id}\n ${message}\n the router rendered an empty component in its place, so nothing inside this route mounted.`,\n { timestamp: true }\n );\n }\n );\n },\n hotUpdate({ server, modules, file }) {\n const absoluteRouterRoot = path.resolve(server.config.root, routerRoot);\n const fileRelativePath = path.relative(server.config.root, file);\n if (this.environment?.name === \"ssr\" && isPathInsideDirectory(file, absoluteRouterRoot)) {\n return [];\n }\n let hasRouteUpdate = false;\n const result = modules.map((module) => {\n if (!module.id) return module;\n const moduleFile = module.id.split(\"?\")[0];\n if (isPathInsideDirectory(moduleFile, absoluteRouterRoot)) {\n const relativeRoutePath = path.relative(absoluteRouterRoot, moduleFile);\n module.acceptedHmrExports = /* @__PURE__ */ new Set();\n if (/^(?:\\([^)]+\\)[\\\\/])?_layout\\.[jt]sx?$/.test(relativeRoutePath)) {\n hasRouteUpdate = true;\n }\n }\n return module;\n });\n if (hasRouteUpdate) {\n server.hot.send({\n type: \"custom\",\n event: \"one:route-update\",\n data: { file: fileRelativePath }\n });\n }\n return result;\n }\n };\n}\nexport {\n createRouteModuleHmrPlugin\n};\n//# sourceMappingURL=routeModuleHmrPlugin.js.map\n"],"mappings":";;;;AAEA,SAAS,2BAA2B,YAAY;CAC9C,OAAO;EACL,MAAM;EAQN,gBAAgB,QAAQ;GACtB,OAAO,IAAI,GACT,oBACC,SAAS;IACR,MAAM,KAAK,MAAM,MAAM;IACvB,MAAM,UAAU,MAAM,WAAW;IACjC,OAAO,OAAO,OAAO,MACnB,+BAA+B,GAAG;IAC1C,QAAQ;+FAEA,EAAE,WAAW,KAAK,CACpB;GACF,CACF;EACF;EACA,UAAU,EAAE,QAAQ,SAAS,QAAQ;GACnC,MAAM,qBAAqB,KAAK,QAAQ,OAAO,OAAO,MAAM,UAAU;GACtE,MAAM,mBAAmB,KAAK,SAAS,OAAO,OAAO,MAAM,IAAI;GAC/D,IAAI,KAAK,aAAa,SAAS,SAAS,sBAAsB,MAAM,kBAAkB,GAAG;IACvF,OAAO,CAAC;GACV;GACA,IAAI,iBAAiB;GACrB,MAAM,SAAS,QAAQ,KAAK,WAAW;IACrC,IAAI,CAAC,OAAO,IAAI,OAAO;IACvB,MAAM,aAAa,OAAO,GAAG,MAAM,GAAG,CAAC,CAAC;IACxC,IAAI,sBAAsB,YAAY,kBAAkB,GAAG;KACzD,MAAM,oBAAoB,KAAK,SAAS,oBAAoB,UAAU;KACtE,OAAO,qCAAqC,IAAI,IAAI;KACpD,IAAI,wCAAwC,KAAK,iBAAiB,GAAG;MACnE,iBAAiB;KACnB;IACF;IACA,OAAO;GACT,CAAC;GACD,IAAI,gBAAgB;IAClB,OAAO,IAAI,KAAK;KACd,MAAM;KACN,OAAO;KACP,MAAM,EAAE,MAAM,iBAAiB;IACjC,CAAC;GACH;GACA,OAAO;EACT;CACF;AACF"}