Skip to content

fix: join borderWidth styles if duplicated#285

Merged
Brentlok merged 2 commits intomainfrom
fix/join-styles
Jan 7, 2026
Merged

fix: join borderWidth styles if duplicated#285
Brentlok merged 2 commits intomainfrom
fix/join-styles

Conversation

@Brentlok
Copy link
Copy Markdown
Contributor

@Brentlok Brentlok commented Jan 7, 2026

Summary by CodeRabbit

  • Improvements

    • Border-width utilities now collapse identical per-side values into a single borderWidth property, reducing output and simplifying styles.
  • Tests

    • Updated border-related tests to expect consolidated borderWidth for uniform sides while retaining per-side expectations for directional utilities.
  • Chores

    • Added a general-purpose utility to remove specified keys from objects.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 7, 2026

📝 Walkthrough

Walkthrough

Collapses identical per-side border width properties into a single borderWidth in the RN style output by adding a joinStyles method and BORDER_WIDTH_KEYS, adds a removeKeys utility, and updates tests to expect consolidated borderWidth for non-directional border classes.

Changes

Cohort / File(s) Summary
RN Processor Enhancement
packages/uniwind/src/metro/processor/rn.ts
Added BORDER_WIDTH_KEYS constant and a private joinStyles(styles: Record<string, any>) that collapses borderTopWidth, borderBottomWidth, borderLeftWidth, borderRightWidth into borderWidth when equal. cssToRN() now returns styles after joinStyles. Added import of removeKeys.
Utility Function
packages/uniwind/src/metro/utils/common.ts
Added exported removeKeys<TObj, TKey>(obj, keysToRemove) which returns a new object omitting specified keys using Object.entries/Object.fromEntries.
Test Updates
packages/uniwind/tests/styles-parsing/borders.test.tsx
Updated expectations: base border, border-2, border-4 now assert a single borderWidth property; directional and composite (e.g., border-t, border-x-2) tests still check per-side properties.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped through styles, four sides in view,
I nuzzled each edge till they matched like new,
One gentle width now holds them tight,
A tidy border, snug and light,
Hooray — a rabbit's tidy sight!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: collapsing duplicate borderWidth properties into a single borderWidth style when all four border sides have the same value.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @packages/uniwind/src/metro/processor/rn.ts:
- Around line 281-298: The joinStyles method erroneously checks every key in the
styles object instead of only border-width keys, so replace the condition that
uses keys.every(...) with a check that iterates over BORDER_WIDTH_KEYS (e.g.,
BORDER_WIDTH_KEYS.every(k => styles[k] === borderWidth)) to ensure you only
compare the four border widths; keep the existing removeKeys(styles,
BORDER_WIDTH_KEYS) and returned shape unchanged and use the same borderWidth
value from styles.borderTopWidth.
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c525f5d and 1adbc86.

📒 Files selected for processing (3)
  • packages/uniwind/src/metro/processor/rn.ts
  • packages/uniwind/src/metro/utils/common.ts
  • packages/uniwind/tests/styles-parsing/borders.test.tsx
🧰 Additional context used
🧬 Code graph analysis (2)
packages/uniwind/src/metro/processor/rn.ts (1)
packages/uniwind/src/metro/utils/common.ts (2)
  • isDefined (1-1)
  • removeKeys (107-110)
packages/uniwind/tests/styles-parsing/borders.test.tsx (1)
apps/expo-router/app/sections/border.tsx (1)
  • BorderScreen (7-271)
🔇 Additional comments (5)
packages/uniwind/tests/styles-parsing/borders.test.tsx (1)

23-27: LGTM! Test updates correctly reflect the border width consolidation.

The test assertions now properly validate that uniform border widths are consolidated into a single borderWidth property instead of four directional properties. This aligns with the implementation changes in rn.ts.

packages/uniwind/src/metro/utils/common.ts (1)

107-110: LGTM! Clean and type-safe utility function.

The implementation correctly removes specified keys from an object using Object.entries and Object.fromEntries, with proper TypeScript typing that accurately represents the operation.

packages/uniwind/src/metro/processor/rn.ts (3)

1-1: LGTM! Import correctly added.

The removeKeys import is properly added to support the border width consolidation logic.


167-167: LGTM! Border width keys correctly defined.

The constant properly defines all four directional border width properties that should be consolidated.


192-194: LGTM! Integration of joinStyles is clean.

The cssToRN method correctly calls joinStyles to consolidate border widths before returning the final style entries.

Comment thread packages/uniwind/src/metro/processor/rn.ts
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/uniwind/src/metro/processor/rn.ts (1)

167-167: Consider making the constant readonly for type safety.

For better type safety and to prevent accidental mutation, consider making BORDER_WIDTH_KEYS readonly:

const BORDER_WIDTH_KEYS = ['borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth'] as const

Or:

const BORDER_WIDTH_KEYS: readonly string[] = ['borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth']
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1adbc86 and d92ae5c.

📒 Files selected for processing (1)
  • packages/uniwind/src/metro/processor/rn.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/uniwind/src/metro/processor/rn.ts (1)
packages/uniwind/src/metro/utils/common.ts (2)
  • isDefined (1-1)
  • removeKeys (107-110)
🔇 Additional comments (3)
packages/uniwind/src/metro/processor/rn.ts (3)

1-1: LGTM!

The removeKeys import is correctly added and used in the new joinStyles method.


192-194: LGTM!

The integration of joinStyles into the cssToRN flow is correct. Border width consolidation now happens before the final style entries are returned.


281-298: LGTM! Critical bug from previous review has been fixed.

The implementation correctly consolidates border width properties when all four sides have identical values. The critical bug identified in the previous review (using keys.every instead of BORDER_WIDTH_KEYS.every at line 289) has been properly fixed.

Edge case consideration: If a borderWidth property already exists alongside the four specific border width properties, it will be replaced by the consolidated value. This appears intentional but verify this behavior aligns with expectations.

#!/bin/bash
# Verify that the joinStyles consolidation works correctly with test cases

# Search for test files related to RN processor
fd -e test.ts -e test.tsx -e spec.ts . packages/uniwind/src/metro/processor/

# Look for existing tests of border width handling
rg -n -C3 --type=ts "borderWidth|border.*Width" packages/uniwind/src/metro/processor/ -g "*test*" -g "*spec*"

@Brentlok Brentlok merged commit 2f47b4f into main Jan 7, 2026
2 checks passed
@Brentlok Brentlok deleted the fix/join-styles branch January 7, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant