Skip to content

Commit

Permalink
[Flight] Source Map Actions in Reference Node Loader Transforms (#30755)
Browse files Browse the repository at this point in the history
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.

<img width="574" alt="Screenshot 2024-08-20 at 2 49 07 PM"
src="https://github.com/user-attachments/assets/7710f0e6-2cee-4aad-8d4c-ae985f8289eb">

Unfortunately this technique doesn't seem to work in Firefox nor Safari.
They don't apply the source map for jumping to the definition.
  • Loading branch information
sebmarkbage authored Aug 21, 2024
1 parent dc32c7f commit dd9117e
Show file tree
Hide file tree
Showing 6 changed files with 1,780 additions and 808 deletions.
1 change: 1 addition & 0 deletions fixtures/flight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"react-dev-utils": "^12.0.1",
"react-dom": "experimental",
"react-refresh": "^0.11.0",
"react-server-dom-webpack": "experimental",
"resolve": "^1.20.0",
"resolve-url-loader": "^4.0.0",
"sass-loader": "^12.3.0",
Expand Down
2,166 changes: 1,411 additions & 755 deletions fixtures/flight/yarn.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/react-server-dom-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
},
"dependencies": {
"acorn-loose": "^8.3.0",
"neo-async": "^2.6.1"
"neo-async": "^2.6.1",
"webpack-sources": "^3.2.0"
}
}
Loading

0 comments on commit dd9117e

Please sign in to comment.