Skip to content

Prefetch not working in components with server:defer and top-level await #13297

@ksolberg

Description

@ksolberg

Astro Info

block
Astro                    v5.3.0
Node                     v22.12.0
System                   Windows (x64)
Package Manager          npm
Output                   server
Adapter                  none
Integrations             none

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

No response

Describe the Bug

In the following example only link a works.

All links work if top level await in Deferred.astro is removed.

astro.config.mjs

import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({
  output: 'server',
  prefetch: true
});

index.astro

---
import Deferred from '../components/Deferred.astro';
---

<h1>Home</h1>
<p>{new Date().toString()}</p>
<Deferred server:defer link="/about-a"/>	
<Deferred link="/about-b"/>	

Deferred.astro

---
const { link } = Astro.props;

const getMsg = async () => {
  return new Promise ((resolve) => {
    setTimeout(() => {
      resolve(`This is the message for ${link}`);
    }, 100);
  });
}

const res = await getMsg();
---
<a href={link} data-astro-prefetch>{link}</a>

about-a.astro
about-b.astro

<h1>About</h1>
<a href="/">Home</a>

What's the expected result?

Expect prefetch to work for both links, including the one with server:defer and top level-await.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-dzimzdt7

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)feat: prefetchRelated to the prefetch feature (scope)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions