Skip to content

Fantom: getRenderedOutput() gives a nested Text's children as a string, where FantomJsonObject types them as a list #60281

Backlog

Description

@YevheniiKotyrlo

Description

getRenderedOutput().toJSON() and toJSONObject() declare each node's children as ReadonlyArray<FantomJsonObject | string> (getFantomRenderedOutput.js#L22-L26), but for a <Text> nested in a paragraph the tester gives the nested Text's children as one string: RenderOutput::renderAttributedString writes text["children"] = fragment.string for every fragment whose parent is not the paragraph (RenderOutput.cpp#L97-L119), and #filterJsonObject copies a children that is not an array through as it is (getFantomRenderedOutput.js#L79-L87).

So a test that reads the JSON as its type says gets a string where it expects a list, and a list method such as children.join('') throws a TypeError.

Steps to reproduce

  1. git clone https://github.com/YevheniiKotyrlo/react-native-fantom-reproducer && cd react-native-fantom-reproducer
  2. ./fantom/reproduce.sh rendered-text-children (needs Docker). It clones react/react-native at main, builds Fantom's tester, and runs packages/react-native/Libraries/Text/__tests__/RenderedTextChildren-itest.js, its license and Flow header left out here:
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';

import * as Fantom from '@react-native/fantom';
import * as React from 'react';
import {Text} from 'react-native';

function renderParagraph() {
  const root = Fantom.createRoot();
  Fantom.runTask(() => {
    root.render(<Text>a<Text>bc</Text></Text>);
  });
  return root.getRenderedOutput({props: []}).toJSONObject();
}

describe('getRenderedOutput() of a paragraph holding a nested Text', () => {
  it('gives the nested Text its children as a list', () => {
    expect(JSON.stringify(renderParagraph())).toBe(
      '{"type":"Paragraph","props":{},"children":["a",{"type":"Text","props":{},"children":["bc"]}]}',
    );
  });

  it("joins the nested Text's children", () => {
    const nested = renderParagraph().children[1];
    expect(nested.children.join('')).toBe('bc');
  });
});

The same on a checkout of main: put the file in place, then yarn workspace @react-native/fantom build and yarn fantom packages/react-native/Libraries/Text/__tests__/RenderedTextChildren-itest.js. The script ends with a SUMMARY: line and exits 1 while the nested Text's children are a string and FantomJsonObject still types them as a list, 0 once they are the list ["bc"] or the declared type admits a string, and 2 when the tester does not build or the test fails another way.

Expected: the nested Text's children are ["bc"], as FantomJsonObject declares them, while the paragraph's own text stays a string in its list; or else FantomJsonObject's children type admits a string.

Seen: the nested Text's children are "bc", and nested.children.join('') throws TypeError: undefined is not a function.

React Native Version

main at c4b72b4 (0.88.0 declares the type and writes the fragment the same way)

Affected Platforms

Build - Linux

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

react-native c4b72b416cbca1624b39f3933444c4a4b059b7d2, committed 2026-11-25T01:11:46+00:00
clang version 23.1.3 (https://github.com/llvm/llvm-project 0d261d1ca552c95a8f007e061c787ac7132fbcbc)

Built and run in reactnativecommunity/react-native-android:v22.0 under Docker, as Fantom's CI job builds the tester, with LLVM 23.1.3's Clang.

Stacktrace or Logs

FAIL fantom packages/react-native/Libraries/Text/__tests__/RenderedTextChildren-itest.js (12.312 s)
  getRenderedOutput() of a paragraph holding a nested Text (hermes)
    ✕ gives the nested Text its children as a list (92 ms)
    ✕ joins the nested Text's children (3 ms)

  ● getRenderedOutput() of a paragraph holding a nested Text (hermes) › gives the nested Text its children as a list

    Expected {"type":"Paragraph","props":{},"children":["a",{"type":"Text","props":{},"children":["bc"]}]} but received {"type":"Paragraph","props":{},"children":["a",{"type":"Text","props":{},"children":"bc"}]}.
[…]
  ● getRenderedOutput() of a paragraph holding a nested Text (hermes) › joins the nested Text's children

    TypeError: undefined is not a function

      32 |   it("joins the nested Text's children", () => {
      33 |     const nested = renderParagraph().children[1];
    > 34 |     expect(nested.children.join('')).toBe('bc');
         |                                ^
      35 |   });
[…]
SUMMARY: the nested Text's children are the string "bc", which FantomJsonObject types as ReadonlyArray<FantomJsonObject | string>, so joining them throws a TypeError

MANDATORY Reproducer

https://github.com/YevheniiKotyrlo/react-native-fantom-reproducer

Screenshots and Videos

No response

Activity

  1. dd9vzptywf-cyber commented on Nov 25, 2026

    @dd9vzptywf-cyber

    import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';

    import * as Fantom from '@react-native/fantom';
    import * as React from 'react';
    import {Text} from 'react-native';

    function renderParagraph() {
    const root = Fantom.createRoot();
    Fantom.runTask(() => {
    root.render(abc);
    });
    return root.getRenderedOutput({props: []}).toJSONObject();
    }

    describe('getRenderedOutput() of a paragraph holding a nested Text', () => {
    it('gives the nested Text its children as a list', () => {
    expect(JSON.stringify(renderParagraph())).toBe(
    '{"type":"Paragraph","props":{},"children":["a",{"type":"Text","props":{},"children":["bc"]}]}',
    );
    });

    it("joins the nested Text's children", () => {
    const nested = renderParagraph().children[1];
    expect(nested.children.join('')).toBe('bc');
    });
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions