Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Comments

fix: closing and opening parenthesis should be serialized#271

Merged
Brentlok merged 2 commits intomainfrom
fix/h-screen-safe
Dec 29, 2025
Merged

fix: closing and opening parenthesis should be serialized#271
Brentlok merged 2 commits intomainfrom
fix/h-screen-safe

Conversation

@Brentlok
Copy link
Contributor

@Brentlok Brentlok commented Dec 29, 2025

fixes #268

Summary by CodeRabbit

  • Tests

    • Added comprehensive test coverage for safe-area insets and screen-responsive sizing behavior
    • Enhanced test setup with environment mocking for consistent UI dimension handling
    • Improved test consistency by standardizing screen dimension references
  • Chores

    • Updated internal token serialization handling for improved processing
    • Added standardized test constants for screen dimensions and safe-area values

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

@coderabbitai
Copy link

coderabbitai bot commented Dec 29, 2025

📝 Walkthrough

Walkthrough

This PR fixes a serialization error by extending the shouldBeSerialized predicate to handle parentheses characters, and introduces comprehensive test infrastructure for safe-area insets functionality with new test constants and improved test setup.

Changes

Cohort / File(s) Summary
Serialization Logic
packages/uniwind/src/metro/utils/common.ts
Extended shouldBeSerialized to treat parentheses ( and ) as serializable tokens, addressing failed serialization errors with CSS expressions
Test Constants & Infrastructure
packages/uniwind/tests/consts.ts, packages/uniwind/tests/setup.ts
Added five new test constants (TW_SPACING, SAFE_AREA_INSET_*, SCREEN_*); enhanced setup to mock Dimensions and initialize safe-area insets via Uniwind.updateInsets
Safe-Area Test Coverage
packages/uniwind/tests/styles-parsing/safe-area.test.tsx
New test file validating safe-area inset application and screen-aware sizing across multiple view configurations
Spacing Test Updates
packages/uniwind/tests/styles-parsing/spacing.test.tsx
Refactored to use SCREEN_WIDTH constant instead of hardcoded value for viewport width assertions

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Parentheses now serialize just fine,
Safe areas inset with precise design,
Tests bloom in spring with constants true,
Screen heights and widths—Uniwind shines anew!

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly relates to the main code change: extending serialization to handle parentheses tokens in the common.ts utility.
Linked Issues check ✅ Passed The PR addresses issue #268's serialization failure by fixing parenthesis handling in the serializer, which resolves the reported 'Failed to serialized javascript object' error.
Out of Scope Changes check ✅ Passed Test additions (safe-area tests and test constants) are supporting changes for validating the fix and are within the scope of the PR's objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/h-screen-safe

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 555f3b7 and a146b19.

📒 Files selected for processing (5)
  • packages/uniwind/src/metro/utils/common.ts
  • packages/uniwind/tests/consts.ts
  • packages/uniwind/tests/setup.ts
  • packages/uniwind/tests/styles-parsing/safe-area.test.tsx
  • packages/uniwind/tests/styles-parsing/spacing.test.tsx
🧰 Additional context used
🧬 Code graph analysis (4)
packages/uniwind/tests/styles-parsing/spacing.test.tsx (1)
packages/uniwind/tests/consts.ts (1)
  • SCREEN_WIDTH (10-10)
packages/uniwind/tests/styles-parsing/safe-area.test.tsx (2)
packages/uniwind/tests/utils.ts (1)
  • renderUniwind (6-18)
packages/uniwind/tests/consts.ts (4)
  • SAFE_AREA_INSET_TOP (7-7)
  • SAFE_AREA_INSET_BOTTOM (8-8)
  • TW_SPACING (5-5)
  • SCREEN_HEIGHT (11-11)
packages/uniwind/src/metro/utils/common.ts (1)
packages/uniwind/src/metro/utils/serialize.ts (2)
  • token (14-39)
  • value (48-91)
packages/uniwind/tests/setup.ts (2)
packages/uniwind/src/components/index.ts (1)
  • Dimensions (139-141)
packages/uniwind/tests/consts.ts (4)
  • SCREEN_WIDTH (10-10)
  • SCREEN_HEIGHT (11-11)
  • SAFE_AREA_INSET_TOP (7-7)
  • SAFE_AREA_INSET_BOTTOM (8-8)
🔇 Additional comments (7)
packages/uniwind/src/metro/utils/common.ts (1)

77-78: LGTM! This fix correctly addresses the serialization issue.

Adding parentheses to the serialization predicate is the correct solution for issue #268. CSS functions like calc(), max(), and min() require parentheses to be properly serialized as part of JavaScript template literals. Without this change, expressions containing parentheses would fail serialization, causing the "Failed to serialized javascript object" error reported in the issue.

packages/uniwind/tests/styles-parsing/spacing.test.tsx (2)

3-3: LGTM! Good refactoring to use shared constants.

Importing SCREEN_WIDTH from the shared constants improves test maintainability and consistency.


28-28: LGTM! Improved test clarity with constants.

Replacing the hardcoded 375 with SCREEN_WIDTH / 2 makes the test expectation explicit and self-documenting. The updated mock screen width (390) represents a more current device dimension.

packages/uniwind/tests/setup.ts (2)

3-8: LGTM! Proper test environment mocking.

Mocking Dimensions.get with fixed values ensures deterministic test behavior across different environments. The mock dimensions (390×844) represent realistic device dimensions and will make viewport-related tests consistent.


25-30: LGTM! Safe area insets properly initialized for tests.

The updateInsets call provides a consistent safe area context for testing. The values align with the constants defined in consts.ts and enable the new safe-area tests to validate inset-dependent layouts correctly.

packages/uniwind/tests/consts.ts (1)

5-11: LGTM! Well-chosen test constants.

These constants provide a single source of truth for test expectations and improve maintainability:

  • TW_SPACING = 4 aligns with Tailwind's default spacing scale
  • Safe area insets and screen dimensions represent realistic device values (iPhone 12/13/14 Pro)
  • Centralizing these values makes tests easier to update and understand
packages/uniwind/tests/styles-parsing/safe-area.test.tsx (1)

1-23: LGTM! Comprehensive safe-area test coverage.

This test effectively validates the safe-area inset functionality:

  • p-safe correctly applies top and bottom safe area padding
  • pt-safe-offset-4 properly combines safe area with additional spacing offset
  • mb-safe-or-4 validates safe-or-fallback behavior
  • h-screen-safe correctly calculates available screen height excluding safe areas

The test assertions align well with the constants defined in consts.ts and the test setup in setup.ts.


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

@Brentlok Brentlok merged commit 3743a91 into main Dec 29, 2025
2 checks passed
@Brentlok Brentlok deleted the fix/h-screen-safe branch December 29, 2025 15:44
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.

Uniwind Error - Failed to serialized javascript object

1 participant