-
Notifications
You must be signed in to change notification settings - Fork 46
fix: handle multiline classes #610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+24
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
20 changes: 20 additions & 0 deletions
20
packages/uniwind/tests/native/styles-parsing/multiline.test.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import * as React from 'react' | ||
| import View from '../../../src/components/native/View' | ||
| import { TW_RED_500 } from '../../consts' | ||
| import { renderUniwind } from '../utils' | ||
|
|
||
| describe('Multiline', () => { | ||
| test('Multiline classes are handled', () => { | ||
| const { getStylesFromId } = renderUniwind( | ||
| <View | ||
| className={`bg-red-500 | ||
| border-2`} | ||
| testID="multiline" | ||
| />, | ||
| ) | ||
|
|
||
| const multilineStyles = getStylesFromId('multiline') | ||
| expect(multilineStyles.backgroundColor).toBe(TW_RED_500) | ||
| expect(multilineStyles.borderWidth).toBe(2) | ||
| }) | ||
| }) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a native
classNameuses tabs without a newline, such asbg-red-500\tborder-2, this condition selects the space-only split and treats both classes as one unknown token. Native rendering then silently omits both styles, while the web resolver accepts the same whitespace-separated input.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will resolve in performance drop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a fair point —
split(/\s+/).filter(Boolean)is measurably slower thansplit(' ')on the hot path. Given that the PR already benchmarks the overhead carefully, always using the regex split would undermine that work.A middle ground: extend the fast-path condition to also cover tabs, keeping the regex split only for non-space whitespace:
This preserves the fast
split(' ')path for the common case while still correctly handling tab-separated class names. If tabs in className strings are genuinely not a concern in your usage (i.e. always space- or newline-separated), then the original code is fine as-is.Tip: You can customize Greptile's behavior for this repo with
.greptile/rules.mdand.greptile/config.json.