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

__self and __source no longer added in development mode using classic runtime #2173

Closed
billyjanitsch opened this issue Dec 11, 2020 · 3 comments

Comments

@billyjanitsch
Copy link
Contributor

Current behavior:

This is actually an issue in Babel, but it was caused by babel/babel#12253 and manifests when using the Emotion preset so I decided to file it here.

Given the following Babel config:

{
  "presets": [
    ["@babel/preset-react", { "development": true }],
    "@emotion/babel-preset-css-prop"
  ]
}

And the following source code:

import * as React from "react";

export default function Foo() {
  return <div />;
}

Using @babel/[email protected] (and its transitive deps that were available as part of the 7.12.7 Babel release), the code would transpile to:

var _jsxFileName = "/Users/billy/work/emotion-classic/index.js";
import * as React from "react";
import { jsx as ___EmotionJSX } from "@emotion/react";
export default function Foo() {
  return ___EmotionJSX("div", {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 4,
      columnNumber: 10
    }
  });
}

With @babel/[email protected], it transpiles to:

var _jsxFileName = "/Users/billy/work/emotion-classic/index.js";
import * as React from "react";
import { jsx as ___EmotionJSX } from "@emotion/react";
export default function Foo() {
  return ___EmotionJSX("div", null);
}

It's interesting because it seems to be the opposite bug as babel/babel#12475.

It might be an ordering issue, if the new transform is injecting the dev stuff at a different point in the Babel lifecycle than the old one. In any case, I wouldn't expect an observable behavioral change in a patch release.

To reproduce:

Reproducing repo is here. Clone and run npm it on either of the two commits to observe the two behaviors.

Expected behavior:

Adding development: true to the React preset config should include the dev transforms.

Environment information:

  • react version: n/a
  • @emotion/react version: n/a
  • @emotion/babel-preset-css-prop: 11.0.0
@Andarist
Copy link
Member

Thanks for the detailed repro and stalking my latest PRs to Babel :trollface: I'll try to look into this asap

@billyjanitsch
Copy link
Contributor Author

Haha I swear I wasn't stalking! I just noticed it while upgrading our preset deps: kensho-technologies/babel-preset#102.

There's actually a second observable change in the Babel PR, btw. When setting runtime: 'classic', it's now an error to set importSource. Previously, the importSource value was just ignored. You can see the necessary change in the PR I linked. Not sure if this change was intentional?

@Andarist
Copy link
Member

Closing here as ive prepared a PR to Babel that should fix this: babel/babel#12495

As to the other issue - could u raise it in Babel and ping me there? I will try to handle it as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants