Starlight 0.42: Less JavaScript, and More JavaScript, All in One Release

Astro · 2 Sept 2026 · 2 min read

#astro

The Starlight team has shipped Starlight 0.42, a release that cleverly balances performance and capability. This update significantly reduces the default JavaScript payload sent to browsers, making documentation sites faster and more accessible, while also introducing new hooks for developers who need to add client-side interactivity. It's a two-pronged approach: trim the fat, then give you the tools to add exactly what you need.

Here are the concrete changes:

  • Automatic removal of unused scripts: Starlight now scans your project and strips out any JavaScript that isn't used by your current configuration or components. This often results in a ~20-30% reduction in bytes shipped, directly improving Core Web Vitals like LCP and TTI. The logic is built into the build process, so no extra configuration is required.
  • New client:visible and client:idle directives for islands: These complement the existing client:load directive, giving you finer control over when interactive components load. Use client:visible for above-the-fold content and client:idle for less critical widgets, all with a simple client:* attribute on any framework component.
  • Enhanced <Code> component with line highlighting and copy button: The built-in code block component now includes a copy button and supports line highlighting via the data-language attribute. This is rendered as a static enhancement until JavaScript loads, so it degrades gracefully.
  • Exposed beforeHydration and afterHydration hooks in the API: For framework integrations, these new lifecycle hooks allow custom logic to run just before or after a component hydrates, enabling smoother interactions with third-party libraries.

This release matters because it addresses a common tension in static site generators: the desire for zero-JavaScript output versus the need for dynamic features. By automatically dropping unused code, Starlight encourages a lean default without sacrificing developer experience. The new directives and hooks give you surgical control over what becomes interactive and when, which is crucial for performance budgets. For documentation sites, this means faster loading on slow connections and better search engine rankings, while still allowing for rich elements like live code samples or search overlays. Upgrade your dependency to @astrojs/[email protected] to take advantage of these improvements.

Source: https://astro.build/blog/starlight-042/

Related

auto-curated · source linked above ← all news