react / react/react-native

StyleSheet.flatten with a falsy value returns undefined

オープン
#46,293 コメント 3 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

API: StyleSheet Issue: Author Provided Repro
主要言語
C++
スター
127k
フォーク
25.3k
平均マージ
1日 23時間
マージ済み PR(30日)
4

説明

Description

On iOS and Android (not web), calling StyleSheet.flatten with null/undefined/false returns undefined.

The TypeScript signature of flatten is flatten<T>(style?: StyleProp<T>): T. null/undefined/false are valid StyleProps, so passing them to flatten should be valid, but flatten is supposed to return T (some style object), and undefined is usually not a valid T.

Widening the return type of flatten to T | undefined is an option, but would be a public API change. I think changing the function to return {} for falsy values is more correct, since you probably want to get a final computed, flattened style object, and don't care what the input was or if it was falsy.

Steps to reproduce

On iOS or Android:

console.log(typeof StyleSheet.flatten(false)) // => 'undefined'
React Native Version

0.75.2

Affected Platforms

Runtime - Android, Runtime - iOS

Output of npx react-native info
System:
  OS: macOS 14.2
  CPU: (8) arm64 Apple M2
  Memory: 339.17 MB / 8.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.3.0
    path: ~/.volta/tools/image/node/22.3.0/bin/node
  Yarn:
    version: 3.6.4
    path: ~/.volta/tools/image/yarn/4.3.1/bin/yarn
  npm:
    version: 10.8.1
    path: ~/.volta/tools/image/node/22.3.0/bin/npm
  Watchman:
    version: 2024.07.01.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/hazel/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK: Not Found
IDEs:
  Android Studio: Not Found
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java: Not Found
  Ruby:
    version: 2.7.4
    path: /Users/hazel/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.75.2
    wanted: 0.75.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: fals
Stacktrace or Logs
N/A
Reproducer

https://snack.expo.dev/@catboyfan/stylesheet-flatten-undefined

Screenshots and Videos

No response

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず StyleSheet.flatten の実装とその TypeScript 宣言を見つけ、次にリンクされた Snack を使って iOS または Android で動作を再現します。null、undefined、false の入力を確認します。falsy 値が公開されている戻り値の型に従う空のスタイルオブジェクトを一貫して生成すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
react-native, typescript
領域
mobile-dev
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。