feat: skip unsafe Unistyles dynamic styles#22
Open
NikhilRW wants to merge 1 commit into
Open
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.
Comment on lines
+216
to
+225
| 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'; | ||
| } |
Comment on lines
+62
to
+66
| shouldBail: () => | ||
| hasBlacklistedProperty( | ||
| path, | ||
| usesUnistylesStyle ? viewBlacklistedPropertiesWithoutStyle : viewBlacklistedProperties | ||
| ), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: