rsbuild-plugin-react-router
Version:
React Router plugin for Rsbuild
46 lines (45 loc) • 2.37 kB
TypeScript
import type { Rspack } from '@rsbuild/core';
export declare const DEV_HMR_RUNTIME_MODULE_ID = "virtual/react-router/hmr-runtime";
export declare const isRspackSwcReactRefreshEnabled: (rspackConfig: Rspack.Configuration) => boolean;
/**
* Resolves the `react-refresh/runtime` module that
* `@rspack/plugin-react-refresh` injects into the web bundle. The resolution
* walks the same dependency chain the refresh plugin uses so the returned file
* is the exact runtime instance already present in the browser module graph.
* Returns `undefined` when React Fast Refresh is unavailable, in which case
* dev HMR falls back to full reloads.
*/
export declare const resolveReactRefreshRuntimePath: (rootPath: string) => string | undefined;
/**
* The HDR revision module is a real file (not a virtual module) because it
* must wake the web compiler through the regular file watcher: the browser
* HMR runtime imports it, so bumping the revision produces a web hot update
* whenever server code changes, which the client answers by revalidating
* React Router loader data.
*/
export declare const DEV_HDR_REVISION_RELATIVE_PATH = ".react-router/hdr-revision.mjs";
export declare const getDevHdrRevisionFilePath: (rootPath: string) => string;
export type DevHdrRevisionSignal = {
/** Writes the initial revision module so the first compile can resolve it. */
ensure: () => void;
/** Increments the revision, signaling hot data revalidation to the client. */
bump: () => void;
};
export declare const createDevHdrRevisionSignal: ({ filePath, onError, }: {
filePath: string;
onError?: (error: Error) => void;
}) => DevHdrRevisionSignal;
/**
* Browser-side HMR runtime shared by all route client entries in development.
*
* This mirrors React Router's Vite HMR contract (see `refresh-utils.mjs` in
* `@react-router/dev`): route module updates are applied by patching
* `window.__reactRouterRouteModules` while preserving the previous component
* identities (React Fast Refresh swaps their implementations in place),
* recreating the client routes with revalidation opt-out, revalidating loader
* data, and finally performing a React refresh.
*/
export declare const generateDevHmrRuntimeModule: ({ reactRefreshRuntimePath, hdrRevisionFilePath, }: {
reactRefreshRuntimePath: string;
hdrRevisionFilePath: string;
}) => string;