feat: skip unsafe Unistyles dynamic styles#22
Conversation
✅ Deploy Preview for react-native-boost ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR updates the react-native-boost Babel plugin to detect react-native-unistyles styles in JSX and avoid optimizing View/Text components when the Unistyles styles are dynamic (runtime-dependent), while still allowing optimization for provably static Unistyles styles. It also includes a small Android event payload adjustment in react-native-time-to-render.
Changes:
- Add Unistyles style detection/classification (
none/static/dynamic) in the plugin’s attribute utilities. - Skip
View/Textoptimizations when dynamic Unistyles styles are detected; allowViewoptimization when styles are static Unistyles. - Add optimizer fixture coverage for Unistyles style scenarios (static vs dynamic) for both
ViewandText.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react-native-time-to-render/android/src/main/java/com/timetorender/OnMarkerPaintedEvent.kt | Adjusts event “target” field to use viewTag directly. |
| packages/react-native-boost/src/plugin/utils/common/attributes.ts | Introduces Unistyles style detection logic and status classification helpers. |
| packages/react-native-boost/src/plugin/optimizers/view/index.ts | Skips optimization on dynamic Unistyles styles; conditionally relaxes style blacklisting when Unistyles styles are static. |
| packages/react-native-boost/src/plugin/optimizers/view/tests/fixtures/unistyles-styles/code.js | New fixture input for View optimizer covering Unistyles styles. |
| packages/react-native-boost/src/plugin/optimizers/view/tests/fixtures/unistyles-styles/output.js | Expected output for View optimizer with Unistyles styles. |
| packages/react-native-boost/src/plugin/optimizers/text/index.ts | Skips optimization on dynamic Unistyles styles for Text. |
| packages/react-native-boost/src/plugin/optimizers/text/tests/fixtures/unistyles-styles/code.js | New fixture input for Text optimizer covering Unistyles styles. |
| packages/react-native-boost/src/plugin/optimizers/text/tests/fixtures/unistyles-styles/output.js | Expected output for Text optimizer with Unistyles styles. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (t.isCallExpression(expression)) { | ||
| let status: UnistylesStyleStatus = t.isExpression(expression.callee) | ||
| ? getExpressionUnistylesStyleStatus(path, expression.callee, seen) | ||
| : 'none'; | ||
|
|
||
| for (const argument of expression.arguments) { | ||
| if (!t.isExpression(argument)) continue; | ||
| status = mergeUnistylesStyleStatus(status, getExpressionUnistylesStyleStatus(path, argument, seen)); | ||
| if (status !== 'none') return 'dynamic'; | ||
| } |
| shouldBail: () => | ||
| hasBlacklistedProperty( | ||
| path, | ||
| usesUnistylesStyle ? viewBlacklistedPropertiesWithoutStyle : viewBlacklistedProperties | ||
| ), |
|
Hey, thanks a lot for your PR! This is a tricky one; a couple of things:
However, I do agree that Unistyles is currently effectively broken. The timings of their Babel plugin and our Babel plugin "unfortunately" work in our favor, so that react-native-boost always rewrites I'll dig into this properly alongside some other optimizations I have planned, and figure out whether there's any way we can safely optimize Unistyles-managed components at all, or if Unistyles needs to be documented as a known incompatibility for now. |
Adds Unistyles-aware safety checks to the React Native Boost Babel optimizer.
This change detects
react-native-unistylesstyles created withStyleSheet.create(...)and prevents unsafe optimization when those styles are dynamic. Dynamic Unistyles styles can depend on theme values, runtime state, function styles, variants, conditionals, or other runtime expressions, so replacing those components with Boost native components can break style updates.The optimizer now:
TextandViewwhen they use dynamic Unistyles styles.NativeTextandNativeView.Examples skipped:
Tests run: