Skip to content

feat(proxy): flush streamed html#1271

Merged
a-h merged 3 commits intoa-h:mainfrom
ZackarySantana:fix-stream-proxy
Dec 31, 2025
Merged

feat(proxy): flush streamed html#1271
a-h merged 3 commits intoa-h:mainfrom
ZackarySantana:fix-stream-proxy

Conversation

@ZackarySantana
Copy link
Copy Markdown
Contributor

Description

When using streaming (e.g. the suspense example) and the proxy option from templ generate, streamed in pages will not properly update. This is because they are loaded into memory completely then proxied.

This pr adds some flushing, by sending over tokens as it reads them.

Screenshots

Before:
https://github.com/user-attachments/assets/9f15dc67-82ae-4fa6-8730-2688ee8fa07a

After:
https://github.com/user-attachments/assets/de6f51f3-04da-454d-be41-c636c64b53ca

log.Debug("No content encoding header found")
default:
h.log.Warn(unsupportedContentEncoding, slog.String("encoding", r.Header.Get("Content-Encoding")))
log.Warn(unsupportedContentEncoding, slog.String("encoding", r.Header.Get("Content-Encoding")))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log line using the unwrapped logger seemed unintentional to me, so I changed it to use the wrapped one

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct! The log is updated on line 134 to add context to all log entries.

@ZackarySantana
Copy link
Copy Markdown
Contributor Author

I rebased on main to fix a failing test

@a-h
Copy link
Copy Markdown
Owner

a-h commented Oct 8, 2025

Sorry about the delay, got a bit of a backlog. I will get to this soon, and it sounds like a useful update!

Copy link
Copy Markdown
Owner

@a-h a-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cracking. Thanks.

log.Debug("No content encoding header found")
default:
h.log.Warn(unsupportedContentEncoding, slog.String("encoding", r.Header.Get("Content-Encoding")))
log.Warn(unsupportedContentEncoding, slog.String("encoding", r.Header.Get("Content-Encoding")))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct! The log is updated on line 134 to add context to all log entries.

@a-h a-h merged commit 8662cdb into a-h:main Dec 31, 2025
5 checks passed
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.

2 participants