Skip to content

dispose() fails on HybridObject when used as HybridView prop: failed to define internal native state property #1083

@mfazekas

Description

@mfazekas

What happened?

When a HybridObject is passed as a prop to a HybridView, calling dispose() on the HybridObject during useEffect cleanup throws:

Exception in HostFunction: failed to define internal native state property

Reproduceable Code

import type { HybridView, HybridViewMethods, HybridViewProps } from 'react-native-nitro-modules'
import type { Base } from './Base.nitro'

export interface TestViewProps extends HybridViewProps {
  // ... other props
  hybridData?: Base  // HybridObject as prop
}

unction ChildWithHybridView({ hybridData }: { hybridData: Base }) {
  useEffect(() => {
    return () => {
      // THIS FAILS with "failed to define internal native state property"
      hybridData.dispose()
    }
  }, [hybridData])

  return (
    <TestView
      hybridData={hybridData}  // Pass HybridObject as prop
      // ... other props
    />
  )
}

Relevant log output

DISPOSE - calling hybridData.dispose()...
DISPOSE - ERROR: Error: Exception in HostFunction: failed to define internal native state property

Device

iOS Simulator (iPhone 16 Pro, iOS 18.x)

Nitro Modules Version

0.31.10

Nitrogen Version

No response

Can you reproduce this issue in the Nitro Example app here?

Yes, I can reproduce the same issue in the Example app here

Branch:

Steps to reproduce:

  1. Apply patch to nitro repo (or checkout branch)
  2. Run bun specs in packages/react-native-nitro-test
  3. Run cd example && bun ios
  4. Navigate to "Dispose" tab
  5. Tap "Create Object" → "Hide Child"
  6. Observe error in log

nitro-dispose-hybridview-reproduction.patch

Diff:
https://github.com/mrousavy/nitro/compare/main...mfazekas:nitro:bug/dispose-hybridview-issue?expand=1

Image

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    nitro-coreIssue is related to the Nitro Modules core runtime/C++ codebase

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions