Skip to content

nativeStyleMapping crashes with "true.split is not a function" when mapping value is the boolean shorthand (e.g. TextInput textAlign) #348

Description

@telanflow

Summary

nativeStyleMapping() in src/native/styles/index.ts assumes every mapping value is a dot-path string and calls path.split("."). However, the NativeStyleMapping type — and the built-in components shipped by this package — allow the value to be the boolean shorthand true (meaning "map onto a native prop with the same name"). When such a mapped style is actually present, (true).split throws TypeError: undefined is not a function during render.

Same root cause as #232 / #288 — filing with a precise root-cause trace and a one-line fix that I've verified locally via a patch.

Affected built-in components

Components that ship a boolean-shorthand nativeStyleMapping crash as soon as the mapped style is applied:

  • components/TextInput.tsx{ textAlign: true } — triggered by text-right / text-center / text-left
  • components/ImageBackground.tsx{ backgroundColor: true } — triggered by any bg-*

(ActivityIndicator / Button use { color: "color" }, a string path, so they don't hit this.)

Reproduction

import { TextInput } from "react-native-css/components"; // or via nativewind v5
<TextInput className="text-right" value="x" onChangeText={() => {}} />

Render → TypeError: undefined is not a function.

Note it only crashes when the mapped style is actually present: when textAlign is absent, styleValue === undefined short-circuits via continue, which is why text-left-less inputs render fine and the crash looks intermittent.

Root cause

src/native/styles/index.ts:

for (const [key, path] of Object.entries(config.nativeStyleMapping)) {
  const styleValue = source[key];
  delete source[key];
  if (styleValue === undefined) {
    continue;
  }
  let target = props;
  const tokens = path.split(".");   // path === true  ->  true.split is not a function
  ...
}

useNativeCss.ts casts value.nativeStyleMapping as Record<string, string>, but the runtime value is { textAlign: true }, so path is the boolean true.

Suggested fix

Treat true as the same-name shorthand (target prop named key), matching the true | DotNotation type:

const tokens = (typeof path === "string" ? path : key).split(".");

Environment

  • react-native-css 3.0.7 (latest)
  • nativewind 5.0.0-preview.3
  • react-native 0.85.3 / React 19.2.3
  • Hermes, iOS

Related: #232, #288, #251

Metadata

Metadata

Assignees

No one assigned

    Labels

    auto-triagedIssue has been automatically triaged by the auto-triage workflowbugSomething isn't workingconfirmedBug reproduced and confirmed by triageready for releaseAvailable as part of the latest nightly release but not yet available on npm

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions