Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/wojtekmaj/vite-plugin-react-fallback-throttle. Vite plugin for configuring FALLBACK_THROTTLE_MS in React 19
Something went wrong. Try again.
1.4 kB · 47 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748import type { PluginOption } from 'vite';
export default function viteReactFallbackThrottlePlugin(throttleMs = 0): { name: string; transform: { filter: { id: { include: string[] } }; handler: (src: string, id: string) => { code: string; map: null }; };} { return { name: 'vite-plugin-react-fallback-throttle', transform: { filter: { id: { include: [ '**/react-dom-client.development.js', '**/react-dom-profiling.development.js', '**/react-dom-client.production.js', '**/react-dom*.js{?*,}', '**/vitest-browser-react.js{?*,}', ], }, }, handler(src) { const srcWithReplacedFallbackThrottle = src // development .replace('FALLBACK_THROTTLE_MS = 300,', `FALLBACK_THROTTLE_MS = ${throttleMs},`) // production .replace( '((exitStatus = globalMostRecentFallbackTime + 300 - now())', `((exitStatus = globalMostRecentFallbackTime + ${throttleMs} - now())`, ) .replace( '300 > now() - globalMostRecentFallbackTime)', `${throttleMs} > now() - globalMostRecentFallbackTime)`, );
const result = { code: srcWithReplacedFallbackThrottle, map: null, };
return result; }, }, } satisfies PluginOption;}