Skip to content

Commit 8964e05

Browse files
authored
fix: nativewind broken by import source being overwritten in default case (#1315)
1 parent 10922d5 commit 8964e05

File tree

5 files changed

+103
-10
lines changed

5 files changed

+103
-10
lines changed

.changeset/rude-icons-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@callstack/repack": patch
3+
---
4+
5+
Fix nativewind issue caused by jsx import source being overwritten to undefined when using babel-swc-loader

apps/tester-app/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PODS:
22
- boost (1.84.0)
3-
- callstack-repack (5.2.0):
3+
- callstack-repack (5.2.2):
44
- boost
55
- DoubleConversion
66
- fast_float
@@ -2930,7 +2930,7 @@ EXTERNAL SOURCES:
29302930

29312931
SPEC CHECKSUMS:
29322932
boost: 7e761d76ca2ce687f7cc98e698152abd03a18f90
2933-
callstack-repack: 9c91d2c48b139e38919c656474f43ab0494b4c21
2933+
callstack-repack: c874fe60c49dcf3067bca0627b7ace673589737c
29342934
DoubleConversion: cb417026b2400c8f53ae97020b2be961b59470cb
29352935
fast_float: b32c788ed9c6a8c584d114d0047beda9664e7cc6
29362936
FBLazyVector: a867936a67af0d09c37935a1b900a1a3c795b6d1
@@ -3011,7 +3011,7 @@ SPEC CHECKSUMS:
30113011
RNWorklets: 20451b83d42e7509f43599b405993e57e3a038af
30123012
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
30133013
SwiftyRSA: 8c6dd1ea7db1b8dc4fb517a202f88bb1354bc2c6
3014-
Yoga: 00013dd9cde63a2d98e8002fcc4f5ddb66c10782
3014+
Yoga: b01392348aeea02064c21a2762a42893d82b60a7
30153015

30163016
PODFILE CHECKSUM: 6d7cbe03444d5e87210979fb32a0eca299d758fe
30173017

packages/repack/src/loaders/babelSwcLoader/__tests__/__snapshots__/babelSwcLoader.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ exports[`partitionTransforms only custom transforms are excluded from included s
3737
},
3838
"transform": {
3939
"react": {
40-
"importSource": undefined,
41-
"runtime": undefined,
40+
"importSource": "react",
41+
"runtime": "automatic",
4242
"useBuiltins": true,
4343
},
4444
},

packages/repack/src/loaders/babelSwcLoader/__tests__/swc.test.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,90 @@ describe('swc transforms support detection', () => {
175175
);
176176
});
177177

178+
it('should apply default react transform when plugin has no react transform options', () => {
179+
const inputConfig: SwcLoaderOptions = {
180+
jsc: {
181+
transform: { react: {} },
182+
},
183+
};
184+
const { swcConfig } = getSupportedSwcCustomTransforms(
185+
[['transform-react-jsx', {}]],
186+
inputConfig
187+
);
188+
189+
expect(swcConfig.jsc?.transform?.react).toEqual({
190+
runtime: 'automatic',
191+
importSource: 'react',
192+
});
193+
});
194+
195+
it('should preserve existing react transform config when plugin has none', () => {
196+
const inputConfig: SwcLoaderOptions = {
197+
jsc: {
198+
transform: {
199+
react: { runtime: 'automatic', importSource: 'nativewind' },
200+
},
201+
},
202+
};
203+
const { swcConfig } = getSupportedSwcCustomTransforms(
204+
[['transform-react-jsx', {}]],
205+
inputConfig
206+
);
207+
208+
expect(swcConfig.jsc?.transform?.react).toEqual({
209+
runtime: 'automatic',
210+
importSource: 'nativewind',
211+
});
212+
});
213+
214+
it('should use plugin importSource option for react transform', () => {
215+
const inputConfig: SwcLoaderOptions = {
216+
jsc: {
217+
transform: {
218+
react: {},
219+
},
220+
},
221+
};
222+
const { swcConfig } = getSupportedSwcCustomTransforms(
223+
[
224+
[
225+
'transform-react-jsx',
226+
{ runtime: 'automatic', importSource: 'nativewind' },
227+
],
228+
],
229+
inputConfig
230+
);
231+
232+
expect(swcConfig.jsc?.transform?.react).toEqual({
233+
runtime: 'automatic',
234+
importSource: 'nativewind',
235+
});
236+
});
237+
238+
it('should use plugin importSource option for react transform and override existing importSource', () => {
239+
const inputConfig: SwcLoaderOptions = {
240+
jsc: {
241+
transform: {
242+
react: { importSource: 'preact' },
243+
},
244+
},
245+
};
246+
const { swcConfig } = getSupportedSwcCustomTransforms(
247+
[
248+
[
249+
'transform-react-jsx',
250+
{ runtime: 'automatic', importSource: 'nativewind' },
251+
],
252+
],
253+
inputConfig
254+
);
255+
256+
expect(swcConfig.jsc?.transform?.react).toEqual({
257+
runtime: 'automatic',
258+
importSource: 'nativewind',
259+
});
260+
});
261+
178262
it('configures modules commonjs options based on provided config (snapshot)', () => {
179263
const inputConfig: SwcLoaderOptions = {};
180264
const { swcConfig } = getSupportedSwcCustomTransforms(

packages/repack/src/loaders/babelSwcLoader/swc.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ function getTransformReactDevelopmentConfig(
7777

7878
function getTransformReactRuntimeConfig(
7979
swcConfig: SwcLoaderOptions,
80-
reactRuntimeConfig: Record<string, any> = {
81-
runtime: 'automatic',
82-
}
80+
reactRuntimeConfig: Record<string, any> = {}
8381
): SwcLoaderOptions {
8482
return {
8583
...swcConfig,
@@ -89,8 +87,14 @@ function getTransformReactRuntimeConfig(
8987
...swcConfig.jsc?.transform,
9088
react: {
9189
...swcConfig.jsc?.transform?.react,
92-
runtime: reactRuntimeConfig.runtime,
93-
importSource: reactRuntimeConfig.importSource,
90+
runtime:
91+
reactRuntimeConfig.runtime ??
92+
swcConfig.jsc?.transform?.react?.runtime ??
93+
'automatic',
94+
importSource:
95+
reactRuntimeConfig.importSource ??
96+
swcConfig.jsc?.transform?.react?.importSource ??
97+
'react',
9498
},
9599
},
96100
},

0 commit comments

Comments
 (0)