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

Fix source maps and simplify getApolloContext to avoid global symbols. #7371

Merged
merged 4 commits into from
Nov 24, 2020

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Nov 24, 2020

The problems with source maps reported by @Billy- in #7370 likely snuck in when we switched back from Rollup to tsc for compiling TypeScript to ESM in #6694.

Thanks to @Billy-'s reproduction, I was able to simplify getApolloContext to avoid relying on global Symbol properties. However, React.createContext is still undefined in that module, because webpack resolves react to @apollo/client/react/index.js, which suggests to me that module resolution must be misconfigured in that application. This is not a problem that Apollo Client can solve, though this PR may help somewhat.

Finally, webpack and/or ts-loader seem to prefer import * as React from 'react' over import React from 'react', and the generated code looks fine to me (both CJS and ESM), so I updated those imports in a few other places.

I was surprised and frustrated to find that tsc does not honor the
--inlineSources compiler option unless source maps are inlined into the
generated source files (the --inlineSourceMap option).

Since we definitely do not want to inline source maps into source files,
we have to use a script to add the sourcesContent property to the .js.map
files generated by tsc.

Fortunately, Rollup gets this right when generating .cjs.js.map files.

Partially fixes #7370.
This seems to be what some versions of TypeScript prefer.
@benjamn benjamn added this to the Post 3.0 milestone Nov 24, 2020
@benjamn benjamn self-assigned this Nov 24, 2020
@benjamn benjamn changed the title Fix source maps and simplify getApolloContext to avoid global properties. Fix source maps and simplify getApolloContext to avoid global symbols. Nov 24, 2020
@benjamn benjamn merged commit 9d837b2 into main Nov 24, 2020
@benjamn benjamn deleted the 7370-fix-source-maps-and-simplify-getApolloContext branch November 24, 2020 21:04
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants