Skip to content

test(ios): failing harness test for blank RiveView after Fabric recreates the view - #372

Open
mfazekas wants to merge 2 commits into
mainfrom
claude/pr-365-issue-reproduction-20d90f
Open

test(ios): failing harness test for blank RiveView after Fabric recreates the view#372
mfazekas wants to merge 2 commits into
mainfrom
claude/pr-365-issue-reproduction-20d90f

Conversation

@mfazekas

@mfazekas mfazekas commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Adds a harness test for the blank-view bug reported in #365. Fabric deletes a component view when its subtree stops being mounted — display: 'none', or a react-native-screens screen frozen by enableFreeze(true) — and recreates it from the same, unchanged ShadowNode. On iOS the recreated view is never configured, because nitro's isDirty prop flags live on the shared Props object and the first view instance already consumed them: no file, blank view forever, and play() on the ref JS still holds is a no-op.

The test fails on iOS today and passes on Android, which doesn't recreate the view. The fix is the nitro 0.37.0 bump (mrousavy/nitro#1503 + #1506 + #1510 replace the isDirty scheme with an old/new props diff), landing in a follow-up commit here.

On the shape of the test: it toggles display: 'none' on the parent rather than pulling in react-freeze, since that produces the same delete/recreate with no extra dependency. The oracle needed some care — the harness has no screenshot API, and the stale ref still answers getViewModelInstance(), awaitViewReady() and play() quite happily on the broken build. What does discriminate is a trigger fired on the bound view model instance: it only reaches its listener while a live view advances the state machine. The same assertion runs before the hide/show as a control, so a failure means the view stopped working rather than the probe never having worked.

Verified by rebuilding and reinstalling the app for each arm: iOS without the fix fails, iOS with #365's patch applied passes, Android passes.

Manual reproducer page (drop into any new-arch app)

Both toggles produce the same Fabric delete/recreate: react-freeze is what enableFreeze(true) uses, and display: 'none' needs no dependency at all. Hit Hide + Show — on an unpatched build the box goes solid black and stays there, hybridRef fires never increments, and play() resolves without doing anything.

import { useRef, useState } from 'react';
import { View, Text, StyleSheet, Pressable } from 'react-native';
// ships with react-native-screens
import { Freeze } from 'react-freeze';
import {
  RiveView,
  useRiveFile,
  Fit,
  type RiveViewRef,
} from '@rive-app/react-native';

type Mode = 'freeze' | 'display';

export default function FreezeRemountBlank() {
  const [mode, setMode] = useState<Mode>('freeze');
  const [hidden, setHidden] = useState(false);
  const [refFires, setRefFires] = useState(0);
  const [playResult, setPlayResult] = useState('—');
  const viewRef = useRef<RiveViewRef | null>(null);
  const { riveFile, error } = useRiveFile(require('./rewards.riv'));

  const rive = riveFile && (
    <RiveView
      file={riveFile}
      autoPlay={true}
      fit={Fit.Cover}
      style={styles.rive}
      hybridRef={{
        f: (ref) => {
          viewRef.current = ref;
          setRefFires((n) => n + 1);
        },
      }}
    />
  );

  return (
    <View style={styles.container}>
      <View style={styles.row}>
        {(['freeze', 'display'] as Mode[]).map((m) => (
          <Pressable
            key={m}
            onPress={() => {
              setHidden(false);
              setMode(m);
            }}
            style={[styles.button, mode === m && styles.buttonActive]}
          >
            <Text style={styles.buttonText}>
              {m === 'freeze' ? 'react-freeze' : 'display:none'}
            </Text>
          </Pressable>
        ))}
      </View>

      <View style={styles.row}>
        <Pressable onPress={() => setHidden((h) => !h)} style={styles.button}>
          <Text style={styles.buttonText}>{hidden ? 'Show' : 'Hide'}</Text>
        </Pressable>
        <Pressable
          onPress={() => {
            setHidden(true);
            setTimeout(() => setHidden(false), 300);
          }}
          style={styles.button}
        >
          <Text style={styles.buttonText}>Hide + Show</Text>
        </Pressable>
        <Pressable
          onPress={() => {
            setPlayResult('pending');
            viewRef.current
              ?.play()
              .then(() => setPlayResult('resolved'))
              .catch((e: unknown) => setPlayResult(`rejected: ${String(e)}`));
          }}
          style={styles.button}
        >
          <Text style={styles.buttonText}>play()</Text>
        </Pressable>
      </View>

      <Text style={styles.status}>
        hidden: {String(hidden)} · hybridRef fires: {refFires} · play():{' '}
        {playResult}
      </Text>
      {error != null && (
        <Text style={styles.status}>Error: {String(error)}</Text>
      )}

      <View style={styles.stage}>
        {mode === 'freeze' ? (
          <Freeze freeze={hidden}>{rive}</Freeze>
        ) : (
          <View style={hidden ? styles.hiddenBox : styles.box}>{rive}</View>
        )}
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1, backgroundColor: '#fff', padding: 12 },
  row: { flexDirection: 'row', gap: 8, marginBottom: 8 },
  button: {
    paddingHorizontal: 12,
    paddingVertical: 8,
    borderRadius: 6,
    backgroundColor: '#444',
  },
  buttonActive: { backgroundColor: '#0a7' },
  buttonText: { color: '#fff', fontWeight: '600' },
  status: { marginBottom: 8, color: '#333' },
  stage: { width: 260, height: 260, backgroundColor: '#000' },
  box: { flex: 1 },
  hiddenBox: { flex: 1, display: 'none' },
  rive: { flex: 1 },
});

Nitro 0.37.0

The bump is the fix. Generated updateProps now diffs the new Props snapshot against the old one instead of consuming shared isDirty flags, so a recreated view re-applies every provided prop. Full iOS harness against a rebuilt app: 30 suites, 210 tests green, view-recreate among them. The peer range moves to >=0.37.0 <0.38, so consumers have to move too.

Three things ride along with it:

  1. Prop parsing moved into Nitro core, taking away the parse site the nitrogen-postprocess.ts shim for Error when assigning undefined to optional view property mrousavy/nitro#1184 used to patch — and that bug is not fixed in 0.37.0: clearing an optional prop still throws mid-commit (RiveView.layoutScaleFactor: Value is null, expected a number, and RiveView.dataBind: Cannot convert "null" to any type in variant<...>). The shim is reinstated one level up: postprocess now injects a parseNullAsCleared wrapper into the generated Props constructor, which reads the raw value through the public RawPropsCompat::at and parses a null-valued optional prop as a cleared one before nitro ever sees it. The fix still ships inside the package and works on stock nitro 0.37.0, so consumers don't need to patch nitro. optional-prop-clear.harness.tsx covers both props and fails without the injection.
  2. The generated EventPropertiesOutput variant is now ordered boolean | number | string, so the two hand-written helpers swap .second and .third.
  3. Both example apps make glog non-modular in post_install. 0.37.0 exposes React's renderer headers in the NitroModules modulemap, and they reach <glog/logging.h>, which includes headers from inside namespace google — illegal once glog is a module, so every target that builds the NitroModules module fails to compile. Same class of breakage as iOS build fails with use_frameworks! since 0.37.0: could not build module 'cxxreact' mrousavy/nitro#1520, whose fix covered only the cxxreact half; ViewComponentDescriptor.hpp still pulls the renderer in on nitro main. This wants an upstream fix — the workaround should come out once Nitro keeps those headers out of its umbrella.

Fabric deletes a component view when its subtree stops being mounted
(display: 'none', or a screen frozen by enableFreeze) and recreates it
from the same, unchanged ShadowNode. On iOS the recreated view is never
configured: nitro's isDirty prop flags live on the shared Props object
and the first view instance already consumed them, so the second one
never gets its file, stays blank, and the ref JS holds points at a dead
view.

Fails on iOS until the nitro bump; passes on Android, which recreates
nothing.
@mfazekas
mfazekas force-pushed the claude/pr-365-issue-reproduction-20d90f branch from dbd78d3 to a4ec8f8 Compare August 23, 2026 22:59
Generated updateProps now diffs the new Props snapshot against the old one
instead of consuming isDirty flags that live on the shared Props object
(mrousavy/nitro#1503, #1506, #1510), so a component view Fabric recreates
from an unchanged ShadowNode gets every provided prop applied again rather
than nothing. That is what view-recreate.harness.tsx was written for. The
peer range moves with it, so consumers have to bump too.

Prop parsing also moved into Nitro core, which takes the old post-process
shim's parse site away — but mrousavy/nitro#1184 is still live there, so
clearing an optional prop throws mid-commit ("RiveView.layoutScaleFactor:
Value is null, expected a number"). Reinstate the shim one level up: the
post-process now injects a parseNullAsCleared wrapper into the generated
Props constructor that reads the raw value through the public
RawPropsCompat::at and parses a null-valued optional prop as a cleared
one. The fix keeps shipping inside the package and works on stock nitro
0.37.0, so consumers are covered without patching nitro themselves.
Covered by a harness test for both the optional<double> and the variant
shape.

The generated EventPropertiesOutput variant is now ordered
`boolean | number | string`, so the two hand-written helpers swap .second
and .third.

Both example apps make glog non-modular in post_install: 0.37.0 exposes
React's renderer headers in the NitroModules modulemap and they reach
<glog/logging.h>, whose headers include from inside `namespace google` —
illegal once glog is a module, so every target that builds the NitroModules
module fails to compile. Nothing in React Native imports glog as a module.
@mfazekas
mfazekas force-pushed the claude/pr-365-issue-reproduction-20d90f branch from a4ec8f8 to 8a919ca Compare August 24, 2026 06:39
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.

1 participant