Skip to content

[nightly and 0.81-rc] View renders as <View_withTag /> in snapshot tests #52764

@mdjastrzebski

Description

@mdjastrzebski

Description

When using React Test Renderer (also when using React Native Testing Library), the plain View component started to be rendered as <View_withTag /> instead of simply <View />:

import React from 'react';
import { View } from 'react-native';
import ReactTestRenderer from 'react-test-renderer';

test('renders correctly', async () => {
  let renderer: ReactTestRenderer.ReactTestRenderer;
  await ReactTestRenderer.act(async () => {
    renderer = ReactTestRenderer.create(<View />);
  });

  expect(renderer.toJSON()).toMatchInlineSnapshot(`<View_withRef />`);
});

This change (regression) will potentially break any snapshot tests, using React Test Renderer and/or React Native Testing Library, which uses View component (basically any view hierarchy snapshot test). Hence, impacting large number of users.

Note: I've already submitted the PR that should fix this as #52622, but there have been some concerns from @yungsters, so submitting this as an issue open to solving in some other way.

Note 2: #52625 suggested by @yungsters as a potential fix, which has been already merged to the used nightly, does not seem to resolve the issue.

Steps to reproduce

  1. Git clone repro repo: https://github.com/mdjastrzebski/repro-react-native-view-with-tag
  2. yarn install && yarn test
  3. Inspect __tests__/issue-repro.test.tsx

React Native Version

0.82 nightly & 0.81-rc

Affected Platforms

Other (please specify)

Output of npx @react-native-community/cli info

System:
  OS: macOS 15.5
  CPU: (10) arm64 Apple M1 Pro
  Memory: 169.09 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 24.4.1
    path: ~/.nvm/versions/node/v24.4.1/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v24.4.1/bin/yarn
  npm:
    version: 11.4.2
    path: ~/.nvm/versions/node/v24.4.1/bin/npm
  Watchman:
    version: 2025.04.28.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/maciej/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK:
    API Levels:
      - "28"
      - "30"
      - "31"
      - "33"
      - "34"
      - "35"
    Build Tools:
      - 30.0.3
      - 33.0.1
      - 34.0.0
      - 35.0.0
    System Images:
      - android-34 | ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
      - android-35 | ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23726.103.2422.13103373
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /usr/bin/javac
  Ruby:
    version: 3.3.6
    path: /Users/maciej/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 19.0.0
    wanted: 19.0.0
  react:
    installed: 19.1.0
    wanted: 19.1.0
  react-native:
    installed: 0.82.0-nightly-20250722-2c3a00b7b
    wanted: 0.82.0-nightly-20250722-2c3a00b7b
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Stacktrace or Logs

import React from 'react';
import { View } from 'react-native';
import ReactTestRenderer from 'react-test-renderer';

test('renders correctly', async () => {
  let renderer: ReactTestRenderer.ReactTestRenderer;
  await ReactTestRenderer.act(async () => {
    renderer = ReactTestRenderer.create(<View />);
  });

  expect(renderer.toJSON()).toMatchInlineSnapshot(`<View_withRef />`);
});

MANDATORY Reproducer

https://github.com/mdjastrzebski/repro-react-native-view-with-tag

Screenshots and Videos

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done / Picked

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions