-
-
Notifications
You must be signed in to change notification settings - Fork 141
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 injection location of generated components via css prop #228
Conversation
src/visitors/transpileCssProp.js
Outdated
program.node.body.push( | ||
let parent = elem | ||
|
||
while (!t.isProgram(parent.parentPath)) { |
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.
I assume this should be a safe thing to do since before we were basically doing the same thing but a file append instead of a sibling prepend to the node tree that we're currently working on.
This is available to test under |
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.
LGTM!
Waiting for codesandbox to work again so I can test these changes against the babel macro |
I'm going to extract out the object css prop and @bpierre's changes into a separate branch, I'm getting weird errors building projects after the insert position changes and it needs more bake time |
9e4e8bc
to
aa02769
Compare
Tested against a babel macro project and a fairly hefty nextjs project with |
generally speaking, the component should be injected just before it's needed, unless it's a styled() HOC and referring to another component in scope, in which case we need to find that component and inject immediately after it
aa02769
to
5d3f1e8
Compare
cleaned up the PR - all the content is the same as before just compacted and rebased |
I'm having this problem when using rollup to bundle, everything seems to be working but the generated code has the styledDiv creation after and outside the React.createElement, so I have error saying createElement received undefined. I assume this is because rollup ast must be different? what can I do? TIA! |
it seems this is the code that sets the injector, if the injector is null, then it adds to the program body, but at the end... for some reason `
} how can I get into the else part of the if? not sure what name should be and where... thx |
oh... nvm just found why this happens, I was using css prop on the main jsx file, I used it now inside a second file, and it works. it seems if css prop is used on main file, it is injecting the new var outside the main scope. thx |
inject the generated components before the tree they're being used in rather than to the end of the file, this fixes situations where a bundler might wrap a component in an IIFE and our component generated from the css prop hasn't been initialized yet (fixes #221, #203)