Skip to content

ui.app.parent getter throws TypeError when accessed from ui.View #98

@blahah

Description

@blahah

Description

When accessing ui.app.parent from within a ui.View, the getter throws a TypeError before the parent reference can be used. This happens even when the view has been properly opened and the parent exists.

Environment

  • Pear Runtime: v2.2.6
  • pear-electron: ^1.7.25
  • Platform: macOS darwin-arm64

Steps to Reproduce

  1. Create a parent app that opens a ui.View:
import ui from 'pear-electron'

const view = new ui.View('./child.html', { /* options */ })
view.on('message', (type, data) => {
  console.log('Message from child:', type, data)
})
await view.open()
await view.send('init', { someData: true })
  1. In the child view (child.html), try to access ui.app.parent:
import ui from 'pear-electron'

// This throws TypeError
const parent = ui.app.parent

Error

Uncaught TypeError: The "listener" argument must be of type function. Received undefined
    at checkListener (events:140:11)
    at Readable.once (events:634:3)
    at get parent (pear-electron/lib/index.js:163:24)

The error originates from the getter implementation itself, not from subsequent usage.

Workaround

Wrap the access in a try-catch:

let parent = null
try {
  parent = ui.app.parent
} catch (err) {
  console.warn('Failed to access ui.app.parent:', err)
}

if (parent) {
  parent.on('message', handleMessage)
  await parent.send('some-message', { data })
}

Expected Behavior

ui.app.parent should return the parent reference (or null if no parent exists) without throwing an error.

Additional Context

The view does work correctly after applying the workaround - messages can be sent and received between parent and child. The issue is specifically in the getter's internal implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions