A tool for people curious about the React Server Components protocol rscexplorer.dev/
rsc react

refactor: use hook filter

authored by

Alexander Lichter and committed by danabra.mov 9538814c 2f85e375

+34 -28
+34 -28
vite.config.js
··· 18 18 return '\0worker:' + resolve(dirname(importer), id.replace('?rolldown-worker', '')); 19 19 } 20 20 }, 21 - async load(id) { 22 - if (!id.startsWith('\0worker:')) return; 23 - const isProd = mode === 'production'; 24 - const { rolldown } = await import('rolldown'); 25 - // Use 'production' or 'development' condition to match React's export conditions 26 - const conditions = isProd 27 - ? ['react-server', 'production', 'browser', 'import', 'default'] 28 - : ['react-server', 'development', 'browser', 'import', 'default']; 29 - const bundle = await rolldown({ 30 - input: id.slice('\0worker:'.length), 31 - platform: 'browser', 32 - resolve: { conditionNames: conditions }, 33 - transform: { 34 - define: { 35 - 'process.env.NODE_ENV': JSON.stringify(isProd ? 'production' : 'development'), 21 + load: { 22 + filter: { 23 + id: { 24 + include: /^\0worker:/, 25 + } 26 + }, 27 + async handler(id) { 28 + const isProd = mode === 'production'; 29 + const { rolldown } = await import('rolldown'); 30 + // Use 'production' or 'development' condition to match React's export conditions 31 + const conditions = isProd 32 + ? ['react-server', 'production', 'browser', 'import', 'default'] 33 + : ['react-server', 'development', 'browser', 'import', 'default']; 34 + const bundle = await rolldown({ 35 + input: id.slice('\0worker:'.length), 36 + platform: 'browser', 37 + resolve: { conditionNames: conditions }, 38 + transform: { 39 + define: { 40 + 'process.env.NODE_ENV': JSON.stringify(isProd ? 'production' : 'development'), 41 + }, 36 42 }, 37 - }, 38 - }); 39 - const { output } = await bundle.generate({ format: 'iife', minify: isProd }); 40 - for (const dep of output[0].moduleIds) { 41 - if (dep.startsWith('/')) this.addWatchFile(dep); 42 - } 43 - await bundle.close(); 44 - return ` 45 - export default URL.createObjectURL(new Blob([${JSON.stringify(output[0].code)}], { type: 'application/javascript' })); 46 - if (import.meta.hot) import.meta.hot.accept(() => location.reload());`; 47 - }, 48 - }; 43 + }); 44 + const { output } = await bundle.generate({ format: 'iife', minify: isProd }); 45 + for (const dep of output[0].moduleIds) { 46 + if (dep.startsWith('/')) this.addWatchFile(dep); 47 + } 48 + await bundle.close(); 49 + return ` 50 + export default URL.createObjectURL(new Blob([${JSON.stringify(output[0].code)}], { type: 'application/javascript' })); 51 + if (import.meta.hot) import.meta.hot.accept(() => location.reload());`; 52 + }, 53 + } 54 + } 49 55 } 50 56 51 57 function serveEmbedPlugin() { ··· 74 80 : ['production', 'browser', 'import', 'default'], 75 81 }, 76 82 build: { 77 - rollupOptions: { 83 + rolldownOptions: { 78 84 input: { 79 85 main: resolve(__dirname, 'index.html'), 80 86 embed: resolve(__dirname, 'embed.html'),