dillon1000/react
Commit
Browse files [Flight Plugin] Scan for "use client" (#26474)
## Summary Our toy webpack plugin for Server Components is pretty broken right now because, now that `.client.js` convention is gone, it ends up adding every single JS file it can find (including `node_modules`) as a potential async dependency. Instead, it should only look for files with the `'use client'` directive. The ideal way is to implement this by bundling the RSC graph first. Then, we would know which `'use client'` files were actually discovered — and so there would be no point to scanning the disk for them. That's how Next.js bundler does it. We're not doing that here. This toy plugin is very simple, and I'm not planning to do heavy lifting. I'm just bringing it up to date with the convention. The change is that we now read every file we discover (alas), bail if it has no `'use client'`, and parse it if it does (to verify it's actually used as a directive). I've changed to use `acorn-loose` because it's forgiving of JSX (and likely TypeScript/Flow). Otherwise, this wouldn't work on uncompiled source. ## Test plan Verified I can get our initial Server Components Demo running after this change. Previously, it would get stuck compiling and then emit thousands of errors. Also confirmed the fixture still works. (It doesn’t work correctly on the first load after dev server starts, but that’s already the case on main so seems unrelated.)
Changed paths5 files
First-parent comparisonpackages/react-server-dom-webpack/package.json ModifiedM packages/react-server-dom-webpack/src/ReactFlightWebpackNodeLoader.js ModifiedM packages/react-server-dom-webpack/src/ReactFlightWebpackNodeRegister.js ModifiedM packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js ModifiedM yarn.lock ModifiedPatch
Files changed
Rendering syntax-highlighted changes…