Skip to content

Commit

Permalink
Add React JSX runtime to default exceptions for inline requires (#1126)
Browse files Browse the repository at this point in the history
Summary:
JSX runtime calls are all over the place in every components. When using inline requires, it doesn't make sense to go through the method call + array access + property access just to call the JSX factory.

Pull Request resolved: #1126

Test Plan:
Before (with inline requires on):

```js
  Object.defineProperty(exports, '__esModule', {
    value: true,
  });
  var _reactNative = _$$_REQUIRE(_dependencyMap[0], "react-native"),
    View = _reactNative.View,
    Text = _reactNative.Text;
  function App() {
    return /*#__PURE__*/_$$_REQUIRE(_dependencyMap[1], "react/jsx-runtime").jsx(View, {
      style: {
        flex: 1,
        backgroundColor: 'green'
      },
      children: /*#__PURE__*/_$$_REQUIRE(_dependencyMap[1], "react/jsx-runtime").jsxs(Text, {
        style: {
          flex: 1
        },
        children: ["whatever ", _$$_IMPORT_ALL(_dependencyMap[2], "./test").A]
      })
    });
  }
```

After (with inline requires on):

```js
  Object.defineProperty(exports, '__esModule', {
    value: true,
    lol: true
  });
  var _reactNative = _$$_REQUIRE(_dependencyMap[0], "react-native"),
    View = _reactNative.View,
    Text = _reactNative.Text;
  var _jsxs = _$$_REQUIRE(_dependencyMap[1], "react/jsx-runtime").jsxs;
  var _jsx = _$$_REQUIRE(_dependencyMap[1], "react/jsx-runtime").jsx;
  function App() {
    return /*#__PURE__*/_jsx(View, {
      style: {
        flex: 1,
        backgroundColor: 'green'
      },
      children: /*#__PURE__*/_jsxs(Text, {
        style: {
          flex: 1
        },
        children: ["whatever ", _$$_IMPORT_ALL(_dependencyMap[2], "./test").A]
      })
    });
  }
```

I added both `react/jsx-runtime` and `react/jsx-dev-runtime` even though currently RN only uses the former.

Reviewed By: motiz88

Differential Revision: D50807788

Pulled By: robhogan

fbshipit-source-id: 7ca9b9fd1b63a7726bd1a60d32815586e54fa7fd
  • Loading branch information
gaearon authored and facebook-github-bot committed Oct 31, 2023
1 parent 20df4ec commit c463b64
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/metro/src/lib/transformHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ type TransformOptionsWithRawInlines = {
+inlineRequires: InlineRequiresRaw,
};

const baseIgnoredInlineRequires = ['React', 'react', 'react-native'];
const baseIgnoredInlineRequires = [
'React',
'react',
'react/jsx-dev-runtime',
'react/jsx-runtime',
'react-native',
];

async function calcTransformerOptions(
entryFiles: $ReadOnlyArray<string>,
Expand Down

0 comments on commit c463b64

Please sign in to comment.