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
- 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 })
- 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.
Description
When accessing
ui.app.parentfrom within aui.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
Steps to Reproduce
ui.View:child.html), try to accessui.app.parent:Error
The error originates from the getter implementation itself, not from subsequent usage.
Workaround
Wrap the access in a try-catch:
Expected Behavior
ui.app.parentshould 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.