ReadableStream passed to an island component argument becomes an empty object
I am passing
ReadableStream to an island component argument becomes an empty objectrender instead of ..catch() to properly deal with potential rejections, but since you haven't asked about error handling, I'll focus on the naming issue.render somewhere else in your code. Also, make sure that the object is indeed an instance of a or has a method available.readable to the component:readable:wss based on how you're using it:undefined at the time you're trying to access it. This could be due to the not being in the expected state or the property not being available on the wss object..then() on it.wss object itself.wss prop is incorrectly closed with a > instead of a }. Here's the corrected prop definition:Promise in a way that should be correct, as you are using .then() to handle the resolved value.Promise at the time when you're trying to call .then() on it. This could happen if is not being passed correctly to the component or if it's not initialized as a Promise.Promise that resolves to an object with readable, writable, extensions, and properties.readable, writable, extensions, and properties, you should verify that it is being set and passed as such.pending, , or ). In contrast, browsers may log a promise as an empty object or with very little information, which can be confusing but is normal behavior..then() method is being called, is undefined. This means that the prop may not be passed correctly to the component, or there is an issue with how the promise is being created or resolved..then() block is not being executed in the browser environment. This could be due to the promise not being resolved or an error occurring before reaching that point.undefined at the time you're trying to call .then() on it in the browser. This could happen if the prop is not being passed correctly to the component or if there's an issue with the promise itself.undefined.GatewayGatewayGatewayGatewayGatewayGatewayGatewayGatewayGatewayGatewayGatewayGatewayGatewayGatewayGatewayreaderreaderreaderreaderreaderreaderreaderreaderreaderreaderreaderreaderreaderrender.read is not a functionreader.read()reader.read()ReadableStreamDefaultReaderreadConnect.tsxConnect.tsxConnect.tsxGateway.tsxGateway.tsxconsole.log(reader)reader.read is not a functionread()read()read()Uncaught TypeError: Cannot read properties of undefined (reading 'then')Uncaught TypeError: Cannot read properties of undefined (reading 'then')Uncaught TypeError: Cannot read properties of undefined (reading 'then')Uncaught TypeError: Cannot read properties of undefined (reading 'then')Uncaught TypeError: Cannot read properties of undefined (reading 'then')Uncaught TypeError: Cannot read properties of undefined (reading 'then')Uncaught TypeError: Cannot read properties of undefined (reading 'then')wss.openedwss.openedWebSocketStreamWebSocketStreamWebSocketStreamWebSocketStreamWebSocketStreamWebSocketStreamopenedopenedconsole.log(wss)console.log(wss)connconnconnconnconnconnconnconnconnconnconnconnconnconnconnconnconnconnconnconnconsole.log(conn)console.log(conn)console.log(conn)console.log(conn)protocolprotocolPromise {}Promise { <state> }<state>fulfilledrejectedconsole.log('message recived')console.log('message received')console.log('message received')<Gateway readable={readable} message={message} />export const Gateway: FunctionComponent<{
reader: ReturnType<Awaited<WebSocketStream['opened']>['readable']['getReader']>
message: Signal<string>
}> = ({ reader, message }) => {
// ...
}<Gateway reader={readable.getReader()} message={message} />export const Gateway: FunctionComponent<{
readable: ReadableStream
message: Signal<string>
}> = ({ readable, message }) => {
const reader = readable.getReader();
// ...
}export const Gateway: FunctionComponent<{
wss: WebSocketStream;
message: Signal<string>;
}> = ({ wss, message }) => {
// ...
}export const Gateway: FunctionComponent<{
wss: WebSocketStream;
message: Signal<string>;
}> = ({ wss, message }) => {
// ...
}// islands/Gateway.tsx
/// <reference lib='deno.unstable' />
import type { FunctionComponent } from 'preact'
import type { Signal } from '@preact/signals'
export const Gateway: FunctionComponent<{
conn: Promise<{
readable: ReadableStream<string | Uint8Array>
writable: WritableStream<string | Uint8Array>
extensions: string
protocol: string
}>
message: Signal<string>
}> = ({ conn, message }) => {
console.log(conn) // gets logged in vs code console as expected but gets logged as an empty object in the browser console
conn.then(({ readable }) => { // error, only shown in browser console, Uncaught TypeError: Cannot read properties of undefined (reading 'then')
readable.getReader().read().then((msg) => {
message.value = msg.value as string
console.log('message recieved')
})
})
return (
<div class='max-w-screen-md mx-auto flex flex-col items-center justify-center'>
<div class='flex gap-8 py-6'>
<button>{message}</button>
</div>
</div>
)
}