Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flight] Source Map Actions in Reference Node Loader Transforms #30755

Merged
merged 4 commits into from
Aug 21, 2024

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Aug 20, 2024

Follow up to #30741.

This is just for the reference Webpack implementation.

If there is a source map associated with a Node ESM loader, we generate new source map entries for every registerServerReference call.

To avoid messing too much with it, this doesn't rewrite the original mappings. It just reads them while finding each of the exports in the original mappings. We need to read all since whatever we append at the end is relative. Then we just generate new appended entries at the end.

For the location I picked the location of the local name identifier. Since that's the name of the function and that gives us a source map name index. It means it jumps to the name rather than the beginning of the function declaration. It could be made more clever like finding a local function definition if it is reexported. We could also point to the line/column of the function declaration rather than the identifier but point to the name index of the identifier name.

Now jumping to definition works in the fixture.

Screenshot 2024-08-20 at 2 49 07 PM

Unfortunately this technique doesn't seem to work in Firefox nor Safari. They don't apply the source map for jumping to the definition.

Copy link

vercel bot commented Aug 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 20, 2024 9:46pm

@react-sizebot
Copy link

react-sizebot commented Aug 20, 2024

Comparing: e831c23...ca1ea70

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB = 1.82 kB 1.82 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 500.37 kB 500.37 kB = 89.80 kB 89.80 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 507.50 kB 507.50 kB = 90.96 kB 90.96 kB
facebook-www/ReactDOM-prod.classic.js = 595.24 kB 595.24 kB = 105.55 kB 105.55 kB
facebook-www/ReactDOM-prod.modern.js = 571.54 kB 571.54 kB = 101.75 kB 101.75 kB
oss-experimental/react-server-dom-webpack/esm/react-server-dom-webpack-node-loader.production.js +60.66% 12.53 kB 20.14 kB +60.72% 3.09 kB 4.97 kB
oss-stable-rc/react-server-dom-webpack/esm/react-server-dom-webpack-node-loader.production.js +60.66% 12.53 kB 20.14 kB +60.72% 3.09 kB 4.97 kB
oss-stable-semver/react-server-dom-webpack/esm/react-server-dom-webpack-node-loader.production.js +60.66% 12.53 kB 20.14 kB +60.72% 3.09 kB 4.97 kB
oss-stable/react-server-dom-webpack/esm/react-server-dom-webpack-node-loader.production.js +60.66% 12.53 kB 20.14 kB +60.72% 3.09 kB 4.97 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-server-dom-webpack/esm/react-server-dom-webpack-node-loader.production.js +60.66% 12.53 kB 20.14 kB +60.72% 3.09 kB 4.97 kB
oss-stable-rc/react-server-dom-webpack/esm/react-server-dom-webpack-node-loader.production.js +60.66% 12.53 kB 20.14 kB +60.72% 3.09 kB 4.97 kB
oss-stable-semver/react-server-dom-webpack/esm/react-server-dom-webpack-node-loader.production.js +60.66% 12.53 kB 20.14 kB +60.72% 3.09 kB 4.97 kB
oss-stable/react-server-dom-webpack/esm/react-server-dom-webpack-node-loader.production.js +60.66% 12.53 kB 20.14 kB +60.72% 3.09 kB 4.97 kB

Generated by 🚫 dangerJS against b3da2c2

So we can use this to generate source maps that point to original code.
Which is a dependency of webpack which is already a peer.
This lets the generated server references point to the original function
declaration (or export declaration if an identifier is exported).
@@ -49,6 +49,7 @@
"react-dev-utils": "^12.0.1",
"react-dom": "experimental",
"react-refresh": "^0.11.0",
"react-server-dom-webpack": "experimental",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was wondering if we need to update the build-for-flight-dev command but that already builds react-server-dom-webpack

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously just copied into the folder but that didn't make yarn consider its dependencies when resolving dependencies.

@sebmarkbage sebmarkbage merged commit dd9117e into facebook:main Aug 21, 2024
185 checks passed
sebmarkbage added a commit that referenced this pull request Aug 22, 2024
Stacked on #30758 and #30755.

This is copy paste from #30755 into the ESM package. We use the
`webpack-sources` package for the source map utility but it's not
actually dependent on Webpack itself. Could probably inline it in the
build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants