Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async generator yielding an object results in [object Object] output #741

Closed
remorses opened this issue Jul 20, 2024 · 4 comments · May be fixed by #743
Closed

Async generator yielding an object results in [object Object] output #741

remorses opened this issue Jul 20, 2024 · 4 comments · May be fixed by #743
Labels
bug Something isn't working

Comments

@remorses
Copy link

What version of Elysia.JS is running?

"elysia": "^1.1.3"

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

import { treaty } from '@elysiajs/eden'
import { sleep } from 'bun'
import { Elysia } from 'elysia'

const app = new Elysia()
    .get('/', async function* generator() {
        await sleep(100) // needed because of another bug
        yield { body: 'Hello Elysia' } // this will be [object Object]
    })
    .listen(3000, async () => {
        const app = treaty<App>('localhost:3000')

        {
            const { data: gen, error } = await app.index.get({})
            if (error) throw error

            for await (const res of gen) {
                console.log(res)
            }
        }
    })

export type App = typeof app

console.log(
    `🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`,
)

What is the expected behavior?

Elysia should call JSON.stringify on every output of an async generator

What do you see instead?

Elysia encodes objects to [object Object]

Additional information

No response

@SaltyAom
Copy link
Member

Should have been fixed with 0a4977a, published under 1.1.4

@remorses
Copy link
Author

Can you check #743? The server should return valid text/event-stream content instead of concatenated JSON strings

@remorses
Copy link
Author

remorses commented Jul 23, 2024

For generators to make sense you need to have a separator between items, otherwise you can't distinguish each item. text/event-stream already has a format for this

@remorses
Copy link
Author

Closing in favor of #742

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants