Skip to content

Bug: SSR script/runtime dedup flags are committed before executable-context confirmation #16525

@thomascolden585-svg

Description

@thomascolden585-svg

Astro Info

<paste output of `astro info` here>


## If this issue only occurs in one browser, which browser is a problem?

N/A (server/runtime emission logic)

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

There appears to be a shared bug pattern in Astro SSR script/runtime dedup logic: global "already rendered" flags are committed before confirming the script/runtime is being emitted into executable DOM context.

From current main source inspection, these paths still look context-blind at the point state is flipped:

  • determineIfNeedsHydrationScript() in packages/astro/src/runtime/server/scripts.ts
  • determinesIfNeedsDirectiveScript() in packages/astro/src/runtime/server/scripts.ts
  • rendererSpecificHydrationScripts dedup path in packages/astro/src/runtime/server/render/common.ts
  • hasRenderedServerIslandRuntime in packages/astro/src/runtime/server/render/common.ts

Because dedup is toggled globally at first encounter, a first hit inside an inert/non-executable context can prevent required script/runtime output in a later executable placement.

What's the expected result?

Dedup state should only be committed once Astro confirms the script/runtime is emitted into an executable DOM context (or dedup should be scoped per effective render context), so later valid placements are not incorrectly skipped.

In other words:

  • encountering a hydration/directive/island runtime path in an inert location should not consume the global "already rendered" state
  • a subsequent executable location should still emit the required script/runtime exactly once

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-9p8z3w1k?file=README.md

(Replace with your real minimal repro before filing. If useful, I can draft a concrete repro layout for this issue.)

Participation

  • I am willing to submit a pull request for this issue.

Link to Minimal Reproducible Example

safdasdf

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugAn edge case that only affects very specific usage (priority)needs reproIssue needs a reproductionpkg: astroRelated to the core `astro` package (scope)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions