Skip to content

fix(repack): lower RN 0.81+ Flow syntax in flow-loader and keep Flow enums in Babel loaders - #1492

Open
whydidoo wants to merge 4 commits into
callstack:mainfrom
whydidoo:fix/1422-flow-lowering
Open

whydidoo wants to merge 4 commits into
callstack:mainfrom
whydidoo:fix/1422-flow-lowering

Conversation

@whydidoo

Copy link
Copy Markdown
Collaborator

Part of #1422 (v5 patch).

Summary

On RN 0.81+, flow-loader (and so getJsTransformRules) emitted invalid JS, because flow-remove-types leaves Flow component/hook/enum/match in place. Separately, @react-native/babel-preset drops Flow enums in babel-loader and babel-swc-loader, so RN's VirtualViewMode.cast() threw at runtime.

flowLoader
  component / hook / enum / match? → RN parser from the preset (hermes / flow-parser)
                                      + flow-strip-types
  otherwise                         → flow-remove-types (as before)
babelLoader (@flow files)           → same RN parser helper, so enums are lowered
  • Enums are lowered to flow-enums-runtime, resolved from the project or react-native, so it works with pnpm.
  • component lowering follows the project's React version: forwardRef on 18, ref as a prop on 19.
  • No new dependencies.
  • Also fixes flow-loader crashing under webpack.

Test plan

  • tests/integration, presets 0.87/0.88 × rspack/webpack: component, hook, enum, match, class fields, source maps, React 18/19, enums in both Babel loaders, getJsTransformRules with a pnpm Flow dependency.
  • New rspack-swc config in tester-app bundles real RN 0.86.3. It failed before this change on View.js.
  • All new tests were red against the old loaders.

…w-loader

flow-remove-types only erases type annotations, so on React Native 0.81+
flow-loader (and getJsTransformRules) emitted invalid JS for `component` /
`hook` declarations, Flow enums and `match` expressions.

Files using them now go through the project's React Native parser
(hermes-parser or flow-parser) and @babel/plugin-transform-flow-strip-types;
all other files still use flow-remove-types. Enums are lowered to
flow-enums-runtime, resolved from the project or from react-native so it
works with isolated installs. Source maps are emitted for lowered files.

Also fix flow-loader crashing under webpack: getOptions() received the
loader context as a schema.

Part of callstack#1422
Flow `component` declarations with a `ref` are lowered to `forwardRef` on
React 18 and pass `ref` as a prop on React 19. Pick the target from the
project's `react` version instead of always assuming React 19.

Part of callstack#1422
@react-native/babel-preset strips Flow enum declarations before its enum
plugin runs, so references such as React Native's VirtualViewMode.cast()
were undefined at runtime. Parse @flow sources with the shared
parseReactNativeSource helper, which lowers enums to flow-enums-runtime
and picks the component lowering target from the project's React version
(hermesParserOverrides still take precedence).

Related to callstack#1422
- detect multi-line `match (...)` in flow-loader's prefilter and cover the
  routing with unit tests
- strip class fields of lowered files like flow-remove-types does: allow
  `declare` fields and honour `ignoreUninitializedFields`
- require @babel/core only when a file needs lowering
- cache flow-enums-runtime and React version lookups per project root
- share the preset lookup and wrap its resolution errors
- pin unused import preservation in a file that is not lowered

Part of callstack#1422
@changeset-bot

changeset-bot Bot commented Oct 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ea31d9b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@callstack/repack Patch
@callstack/repack-plugin-expo-modules Patch
@callstack/repack-plugin-nativewind Patch
@callstack/repack-plugin-reanimated Patch
@callstack/repack-dev-server Patch
@callstack/repack-init Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Oct 10, 2026

Copy link
Copy Markdown

@whydidoo is attempting to deploy a commit to the Callstack Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant