-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
examples: Inject react runtime for ui package #371
examples: Inject react runtime for ui package #371
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/vercel/turbo-site/DiTtxhRZdUoaVtajvxQ2W34exFq2 |
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.
Looks good, just let's get rid of index.tsx's / barrel files aside from the root in ui
and also move tests back to where they were
@jaredpalmer good call, updated with your suggestions! Thanks! |
Without this tsup builds do not work with apps (see vercel/turborepo#371)
This allows us to reference the source maps for individual chunk items when delivering them for HMR updates. We currently send down the update via a `JSON.stringify()` of the updated module's code. We then `eval` this code to generate the new "module", and call registered hot handlers with the new module to update their scopes. Thankfully, we can include a `sourceMappingUrl` comment in the evaled code, so we can get away with deferring creating the source map's content until dev tools is opened. This is a first pass, it really needs to be cleaned up. But at least it's working. Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
What has been changed?
build
anddev
command forkitchen-sink
examples ui package to support components that don't explicitly importReact
.Why?
Starting from React 17, React shipped with the new JSX Transform, allowing components to include JSX without React being in scope (For example, the
Button
component included below). Because of this, it is now very common to write react components without explicitly importing React at all.However, in the current
kitchen-sink
example, doing this will break, and throw:ReferenceError: React is not defined
.How?
In order to support this common use case, we need to instruct
tsup
to inject thereact
runtime into the build. Becausetsup
usesesbuild
, we can leverage --inject to automatically replace a global variable with an import from another file. tsup has supported this argument (although poorly documented) since 5.3.0 (commit)Other
Fixing this will hopefully avoid frustration from new users who want to use an example as a starting point, with minimal changes to the build configuration.