-
Notifications
You must be signed in to change notification settings - Fork 626
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
fix: apply custom serializer to source map endpoint in dev server #1284
base: main
Are you sure you want to change the base?
fix: apply custom serializer to source map endpoint in dev server #1284
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't address the same issue occurring in error symbolication
Yeah we should definitely make sure those are all consistent.
// If the project defines a custom serializer, then we should run it to ensure any | ||
// mutations to the graph are applied in the sourcemap. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to me to run the custom serializer consistently (and I vaguely remember seeing cases where this was broken), but what do you mean by "mutations to the graph"? When during bundling do those occur?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone were to preModules.splice(0,0, { ... })
to add a new module inside of a custom serializer, then it would technically mutate the arguments used to generate the bundle. I can think of two cases like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but it's a little unstable. I'm sniffing if the sourceUrl has a .map
pathname to determine if the serializer should return source maps. This works for the .map
endpoint, but it doesn't account for /symbolicate
where the result is getExplodedSourceMap
and not a standard source map string.
…9463) # Why - The source maps are off-by-1 in development and this causes debugging and errors to be janky. - The cause is related to Metro serializing the graph differently in `.map` requests than it does in `.bundle` requests. - Required change in Metro facebook/metro#1284 <!-- Please describe the motivation for this PR, and link to relevant GitHub issues, forums posts, or feature requests. --> # How - Mutate the premodules to try and mitigate issues like this from happening in the future. - Detect when a serialization request is meant for source maps in development, and return the maps from the serializer. This depends on an upstream fix in Metro (if it doesn't land, we can try something else). - [Update]: I've also added a new system (consider existing implementation legacy) which injects a polyfill that is one line long. We then update this polyfill in the serializer accordingly to ensure source maps stay correct, even in cases such as error handling where Metro serializes them a third way. <!-- How did you build this feature or fix this bug and why? --> # Test Plan - Added an E2E dev server test which pings the source maps and detects if the `__env__` module is included. - Physically attached a debugger and ensured that the sources were aligned in development. <!-- Please describe how you tested this change and how a reviewer could reproduce your test, especially if this PR does not include automated tests! If possible, please also provide terminal output and/or screenshots demonstrating your test/reproduction. --> # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Expo Bot <[email protected]>
…9463) # Why - The source maps are off-by-1 in development and this causes debugging and errors to be janky. - The cause is related to Metro serializing the graph differently in `.map` requests than it does in `.bundle` requests. - Required change in Metro facebook/metro#1284 <!-- Please describe the motivation for this PR, and link to relevant GitHub issues, forums posts, or feature requests. --> # How - Mutate the premodules to try and mitigate issues like this from happening in the future. - Detect when a serialization request is meant for source maps in development, and return the maps from the serializer. This depends on an upstream fix in Metro (if it doesn't land, we can try something else). - [Update]: I've also added a new system (consider existing implementation legacy) which injects a polyfill that is one line long. We then update this polyfill in the serializer accordingly to ensure source maps stay correct, even in cases such as error handling where Metro serializes them a third way. <!-- How did you build this feature or fix this bug and why? --> # Test Plan - Added an E2E dev server test which pings the source maps and detects if the `__env__` module is included. - Physically attached a debugger and ensured that the sources were aligned in development. <!-- Please describe how you tested this change and how a reviewer could reproduce your test, especially if this PR does not include automated tests! If possible, please also provide terminal output and/or screenshots demonstrating your test/reproduction. --> # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Expo Bot <[email protected]>
This PR fixes a problem with debugger on expo projects, caused by prelude lines added to the entry bundle file added by expo. The solution is t0 add the required offset to the prelude causing the problem and scanning for it when receiving source map in the debuger. It is possible that the changes will no longer be needed in future versions of react native as the expo team tries to correct source map generation to include extra lines, for more information read those PRs: - [expo side ](expo/expo#29463) - [metro side](facebook/metro#1284) This is why we add version check before adding lineOffset to initial source map. ### How Has This Been Tested: - open expo project and set a breakpoint, before the changes it would trigger 2 lines above the place it's been set. - save any change in the file containing breakpoint and make sure it still works. - check if links to files generated next to console logs are pointing in to the correct place, again both before and after making changes to the file. - check if error position indicator (when uncaught exception is raised) points to the correct position. ### Additional changes: This PR also fixes a minor mistake with `getReactNativeVersion` utility that does not need to be async and as it is used, we make it synchronous as part of this PR. --------- Co-authored-by: Krzysztof Magiera <[email protected]>
Summary
build
function. In the Expo metro-config, we use the serializer to inject custom pre-modules for things like SSR and client-side environment variables. These changes aren't reflected in the source map endpoint.Changelog: [Fix] Apply custom serializer to source map graph in
.map
endpoint.