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

EventStream convert '\n' to '' #733

Closed
gyhyfj opened this issue Apr 18, 2024 · 1 comment
Closed

EventStream convert '\n' to '' #733

gyhyfj opened this issue Apr 18, 2024 · 1 comment

Comments

@gyhyfj
Copy link

gyhyfj commented Apr 18, 2024

Environment

node 20.12.1
nitropack 2.9.6

Reproduction

// server side
const eventStream = createEventStream(event)
eventStream.push('\n')

// client side
const sse = new EventSource('path/to/sse')
sse.addEventListener('message', e => {
console.log(e.data'')
})

Describe the bug

hope to deliver '\n' to client side, but get ''

Additional context

No response

Logs

No response

@joshmossas
Copy link
Contributor

joshmossas commented Apr 18, 2024

Server sent event messages are delimited by \n\n. So if you send a message that is only a single newline the client will see data:\n\n\n and think that the message has ended after the second \n.

If you want to deliver a message that consists of only '\n' then you will probably need to escape it or wrap it in quotes.

@gyhyfj gyhyfj closed this as completed Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants