Skip to content

fix: add X-Accel-Buffering: no header to text/event-stream responses - #16156

Merged
Rich-Harris merged 2 commits into
mainfrom
unbuffered-event-streams
Jun 24, 2026
Merged

Rich-Harris merged 2 commits into
mainfrom
unbuffered-event-streams

Conversation

@Rich-Harris

Copy link
Copy Markdown
Member

closes #15790, closes #16130. On nginx, responses are buffered by default to spare servers from keeping connections open to slow clients. When the response in question is an event stream, this is a very silly thing to do.

This PR fixes it by adding the x-accel-buffering: no header in those cases.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot

changeset-bot Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f95b9d1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/adapter-node Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread packages/adapter-node/src/handler.js Resolved
@svelte-docs-bot

Copy link
Copy Markdown

@Rich-Harris
Rich-Harris merged commit 2633f6a into main Jun 24, 2026
26 checks passed
@Rich-Harris
Rich-Harris deleted the unbuffered-event-streams branch June 24, 2026 15:55
@github-actions github-actions Bot mentioned this pull request Jun 24, 2026
Rich-Harris pushed a commit that referenced this pull request Jun 24, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @sveltejs/[email protected]

### Minor Changes


- feat: expose `RemoteFormEnhanceInstance` and
`RemoteFormEnhanceCallback` types
([#15816](#15816))


- feat: set value of `submit` fields when form is submitted
([#15979](#15979))


### Patch Changes


- fix: skip `native_navigation` when `__data.json` returns 404 on a
static fallback page
([#16135](#16135))


- fix: ignore third-party monkeypatches in `pushState`/`replaceState`
warning detection ([#15267](#15267))


- fix: snapshot form fields on read
([#16150](#16150))


- fix: strip field prefix before erroring on duplicates
([#16151](#16151))


- fix: call reset function via prototype
([#16138](#16138))


- chore: fix navigation `type` hover info
([#16147](#16147))
## @sveltejs/[email protected]

### Patch Changes


- fix: add `X-Accel-Buffering: no` header to `text/event-stream`
responses to prevent reverse proxies such as nginx from buffering
streamed responses
([#16156](#16156))


- fix: delete existing socket file on startup
([#15449](#15449))

- Updated dependencies
[[`c426c6e`](c426c6e),
[`81f253e`](81f253e),
[`8d3c865`](8d3c865),
[`6bde3b6`](6bde3b6),
[`9161740`](9161740),
[`2184960`](2184960),
[`5e319b6`](5e319b6),
[`e82a0a8`](e82a0a8)]:
  - @sveltejs/[email protected]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
teemingc pushed a commit that referenced this pull request Nov 13, 2026
…rameters in adapter-node (#17687)

adapter-node only adds `X-Accel-Buffering: no` (added in #16156 so nginx
doesn't buffer SSE) when the content type is exactly
`text/event-stream`. A response with a parameter, which is common,
doesn't get it:

```js
// src/routes/events/+server.js
export function GET() {
	return new Response('data: hello\n\n', {
		headers: { 'content-type': 'text/event-stream; charset=utf-8' }
	});
}
```

With adapter-node, `curl -I` on that route has no `x-accel-buffering`
header, so the stream gets buffered behind nginx again. adapter-bun
already checks with `startsWith('text/event-stream')`, so the same app
behaves differently on the two adapters.

This changes the adapter-node check to `startsWith`, matching
adapter-bun.

I added a `/event-stream/charset` route and a test to the adapter-node
`basic` app. On `main` the new test fails with:

```
Expected: "no"
Received: undefined
```

With the change, all 16 tests in that app pass, as do the adapter-node
unit and build tests. `pnpm lint` and `pnpm check` pass too.

---

### Please don't delete this checklist! Before submitting the PR, please
make sure you do the following:

- [ ] It's really useful if your PR references an issue where it is
discussed ahead of time. In many cases, features are absent for a
reason. For large changes, please create an RFC:
https://github.com/sveltejs/rfcs
- [x] This message body should clearly illustrate what problems it
solves.
- [x] Ideally, include a test that fails without this PR but passes with
it.

### Tests

- [x] Run the tests with `pnpm test` and lint the project with `pnpm
lint` and `pnpm check`

### Changesets

- [x] If your PR makes a change that should be noted in one or more
packages' changelogs, generate a changeset by running `pnpm changeset`
and following the prompts. Changesets that add features should be
`minor` and those that fix bugs should be `patch`. Please prefix
changeset messages with `feat:`, `fix:`, or `chore:`.

### Edits

- [x] Please ensure that 'Allow edits from maintainers' is checked. PRs
without this option may be closed.
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

Successfully merging this pull request may close these issues.

[docs?] nginx buffers query.live responses; needs X-Accel-Buffering: no on the stream

3 participants