UNPKG

@tanstack/router-plugin

Version:

Modern and scalable routing for React applications

34 lines (33 loc) 1.32 kB
import { getHandleRouteUpdateCode } from "./handle-route-update.js"; import * as template from "@babel/template"; //#region src/core/hmr/vite-adapter.ts /** * Emits HMR accept code for Vite / native ESM HMR: `import.meta.hot.accept` * with a callback that receives the freshly re-imported module. * * `targetFramework` is currently unused — Vite's framework-specific fast-refresh * plugins handle component body patching via their own accept boundaries — but * we take it for API symmetry with `createWebpackHmrStatement`. */ function createViteHmrStatement(stableRouteOptionKeys, opts = {}) { const handleRouteUpdateCode = getHandleRouteUpdateCode(stableRouteOptionKeys); const routeIdFallback = typeof opts.routeId === "string" ? JSON.stringify(opts.routeId) : "Route.id"; return [template.statement(` if (import.meta.hot) { const hot = import.meta.hot const hotData = hot.data ??= {} hot.accept((newModule) => { if (Route && newModule && newModule.Route) { const routeId = hotData['tsr-route-id'] ?? ${routeIdFallback} if (routeId) { hotData['tsr-route-id'] = routeId } (${handleRouteUpdateCode})(routeId, newModule.Route) } }) } `, { syntacticPlaceholders: true })()]; } //#endregion export { createViteHmrStatement }; //# sourceMappingURL=vite-adapter.js.map