Skip to content

Commit 343aa08

Browse files
author
julusy
committed
fix(mobile): rebuild uniwind patch without dropping pre-existing hunks
The media-query hunk regeneration reset the five patched files to pristine before applying it, silently reverting the state/data selector variant fix and the Metro native-styles fingerprint in those copies. Rebase the media hunk onto main's full patch (installed tree now differs from main's only inside the media branches) and extend the fixture with negative controls for the preserved behaviors: active:/disabled:/data-* stay conditioned, [aria-disabled] compounds stay rejected, and the global.css virtual module keeps its fingerprint argument.
1 parent 7525fc2 commit 343aa08

4 files changed

Lines changed: 946 additions & 22 deletions

File tree

‎apps/mobile/src/lib/uniwind-platform-variants.fixture.cjs‎

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ function createUniwindCompilerLoader(uniwindPackageJson) {
6060
};
6161

6262
const loadBundler = (request) => load(path.join(uniwindRoot, "dist/common", request));
63-
return { loadBundler, uniwindRequire };
63+
return { loadBundler, uniwindRequire, uniwindRoot };
6464
}
6565

6666
async function main() {
67-
const fixtureDir = path.resolve(process.argv[2]);
67+
const fixtureDir = fs.realpathSync(path.resolve(process.argv[2]));
6868
const uniwindPackageJson = require.resolve("uniwind/package.json", {
6969
paths: [fixtureDir],
7070
});
71-
const { loadBundler, uniwindRequire } = createUniwindCompilerLoader(uniwindPackageJson);
71+
const { loadBundler, uniwindRequire, uniwindRoot } =
72+
createUniwindCompilerLoader(uniwindPackageJson);
7273
const { ProcessorBuilder } = loadBundler("bundler/css-processor/processor.js");
7374
const { addMetaToStylesTemplate } = loadBundler(
7475
"bundler/css-processor/addMetaToStylesTemplate.js",
@@ -110,11 +111,17 @@ async function main() {
110111
const payload = compileNativeCSS(bundlerConfig, tailwindCSS);
111112
const styles = {};
112113
for (const [className, entries] of Object.entries(compiled)) {
113-
styles[className] = entries.map(({ native, minWidth, maxWidth }) => ({
114-
native,
115-
minWidth,
116-
maxWidth,
117-
}));
114+
styles[className] = entries.map(
115+
({ native, minWidth, maxWidth, active, focus, disabled, dataAttributes }) => ({
116+
native,
117+
minWidth,
118+
maxWidth,
119+
active: active ?? null,
120+
focus: focus ?? null,
121+
disabled: disabled ?? null,
122+
dataAttributes: dataAttributes ?? null,
123+
}),
124+
);
118125
}
119126
platforms[platform] = {
120127
styles,
@@ -129,7 +136,45 @@ async function main() {
129136
};
130137
}
131138

132-
process.stdout.write(JSON.stringify({ tailwindChecks, platforms }));
139+
// Exercise the real Metro transformer entry point (the shipped
140+
// `dist/metro/transformer.cjs`, not a copy) with a stubbed downstream worker,
141+
// to check what the global.css virtual module actually becomes — including
142+
// the native styles fingerprint that lets dev reloads skip reinitializing.
143+
const transformerPath = path.join(uniwindRoot, "dist/metro/transformer.cjs");
144+
let reinitCode = "";
145+
const Module = require("node:module");
146+
const origLoad = Module._load;
147+
Module._load = function (request, ...rest) {
148+
if (request === "metro-transform-worker") {
149+
return {
150+
transform: async (_config, _root, _file, data) => {
151+
reinitCode = data.toString();
152+
return { output: [{ data: {} }] };
153+
},
154+
};
155+
}
156+
return origLoad.call(this, request, ...rest);
157+
};
158+
process.chdir(fixtureDir);
159+
try {
160+
const { transform } = require(transformerPath);
161+
await transform(
162+
{ uniwind: { cssEntryFile: "./global.css", isExpoProject: false } },
163+
fixtureDir,
164+
"global.css",
165+
Buffer.from(""),
166+
{ platform: "ios", type: "module" },
167+
);
168+
} finally {
169+
Module._load = origLoad;
170+
}
171+
const transformerCheck = {
172+
reinitPayload: reinitCode.includes("Uniwind.__reinit(rt =>"),
173+
fingerprintArg: /, '[0-9a-f]{64}'\);\s*$/.test(reinitCode),
174+
themesArg: reinitCode.includes("['light', 'dark']"),
175+
};
176+
177+
process.stdout.write(JSON.stringify({ tailwindChecks, transformerCheck, platforms }));
133178
}
134179

135180
main().catch((error) => {

‎apps/mobile/src/lib/uniwind-platform-variants.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ interface CompiledStyle {
1919
native: boolean;
2020
minWidth: number;
2121
maxWidth: number;
22+
active: boolean | null;
23+
focus: boolean | null;
24+
disabled: boolean | null;
25+
dataAttributes: Record<string, string> | null;
2226
}
2327

2428
interface FixtureOutput {
@@ -28,6 +32,11 @@ interface FixtureOutput {
2832
iosUtilities: number;
2933
androidUtilities: number;
3034
};
35+
transformerCheck: {
36+
reinitPayload: boolean;
37+
fingerprintArg: boolean;
38+
themesArg: boolean;
39+
};
3140
platforms: Record<
3241
string,
3342
{
@@ -205,3 +214,40 @@ describe("uniwind keeps media rules nested inside class rules attached to the cl
205214
expect(androidEntries?.some((style) => style.native)).toBe(false);
206215
});
207216
});
217+
218+
// The patch file carries three independent uniwind fixes (state/data selector
219+
// variants, the Metro native-styles fingerprint, and this media-query scoping
220+
// fix). Regenerating it for one fix must not silently drop the others — this
221+
// suite exercises the shipped transformer and compiler for the other two.
222+
describe("uniwind patch keeps pre-existing selector and transformer behavior", () => {
223+
let output: FixtureOutput;
224+
225+
beforeAll(() => {
226+
output = runFixture(
227+
'@import "tailwindcss";\n@import "uniwind";\n',
228+
'export const Probe = () => <div className="active:opacity-50 disabled:opacity-50 data-x:underline aria-disabled:text-red-500" />;\n',
229+
);
230+
}, 60_000);
231+
232+
it("keeps state and data variants conditioned, and rejects unsupported compounds", () => {
233+
for (const platform of ["ios", "android"]) {
234+
const styles = output.platforms[platform]?.styles;
235+
expect(styles?.["active:opacity-50"]?.every((style) => style.active === true)).toBe(true);
236+
expect(styles?.["disabled:opacity-50"]?.every((style) => style.disabled === true)).toBe(true);
237+
expect(styles?.["data-x:underline"]?.every((style) => style.dataAttributes?.["data-x"])).toBe(
238+
true,
239+
);
240+
// `[aria-disabled="true"]` is not expressible at runtime; emitting it
241+
// unconditionally (the pre-#9355 behavior) styles the element always.
242+
expect(styles).not.toHaveProperty("aria-disabled:text-red-500");
243+
}
244+
});
245+
246+
it("emits the global.css virtual module with a native styles fingerprint", () => {
247+
expect(output.transformerCheck).toEqual({
248+
reinitPayload: true,
249+
fingerprintArg: true,
250+
themesArg: true,
251+
});
252+
});
253+
});

0 commit comments

Comments
 (0)