Skip to content

Clarify Content-Type Handling When Using Component.Render in Documentation #1260

@hu3bi

Description

@hu3bi

Description:

Currently, when calling Render on a templ component, the Content-Type header is not set automatically. This requires users to manually set the appropriate header (e.g., "text/html; charset=utf-8") when serving components via HTTP.

This behavior can be surprising, especially since templ.Handler (or ComponentHandler) does handle the Content-Type when used with templ.WithContentType.

Proposal:

  • Add clear documentation stating that users must set the Content-Type header themselves when using Component.Render.
  • Optionally, consider whether Component.Render could accept options (similar to templ.Handler) to set the header automatically, or state in the documentation that this isn’t the default.

Benefits:

  • Prevents confusion and subtle bugs when serving HTML responses.
  • Improves the developer experience by making expectations explicit.

As a side note, extend the go comment for the component handler, to make it clear that it should only be used to render static sites.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions