-
Notifications
You must be signed in to change notification settings - Fork 620
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 <34669131+expo-bot@users.noreply.github.com>
…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 <34669131+expo-bot@users.noreply.github.com>
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.