Skip to content

Add helper component for embedding inline scripts #341

@3w36zj6

Description

@3w36zj6

What is the feature you are proposing?

When implementing features like color scheme switching (e.g., light/dark mode) with HonoX, a common issue is that the default theme is applied until an external .js file finishes loading, causing a brief flash of the wrong theme on page load. This is known as FOUC (Flash of Unstyled Content). A widely adopted solution is to embed the color scheme logic as an inline script directly in the delivered HTML, ensuring the correct theme is applied before the page is rendered.

Inline scripts are useful not only for color scheme handling but also for other scenarios, such as injecting initial state, CSP nonce-based initialization, or analytics snippets that must run as early as possible.

For reference, Astro provides a directive for inserting inline scripts1.

I believe it would be helpful if HonoX offered a simple helper component, such as <InlineScript/>, to make embedding inline scripts more convenient and ergonomic.

Footnotes

  1. https://docs.astro.build/en/reference/directives-reference/#isinline

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions