withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.93k stars 2.49k forks source link

Server islands does not support indirect components - "Could not find server component name" #12458

Closed moonlitknight closed 3 days ago

moonlitknight commented 4 days ago

Astro Info

Astro                    v5.0.0-beta.8
Node                     v22.5.1
System                   Linux (x64)
Package Manager          unknown
Output                   server
Adapter                  @astrojs/vercel
Integrations             @astrojs/tailwind
                         @astrojs/solid-js

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

No response

Describe the Bug

tl;dr adding "server:defer" to my component causes error

13:52:48 [ERROR] Could not find server component name
  Stack trace:
    at /usr/app/sluroy/astrosb/node_modules/.pnpm/astro@5.0.0-beta.8_@types+node@22.7.4_jiti@1.21.6_rollup@4.27.2_typescript@5.6.2_yaml@2.5.1/node_modules/astro/dist/runtime/server/render/server-islands.js:35:15
    [...] See full stack trace in the browser, or rerun with --verbose.

My code is unusual insofar as, I do not render the component by name, but rather I instantiate an object that contains the component object and render that. This works fine without server islands, but fails if I add "server:defer".

See the index.astro file in the attached Stackblitz to see the minimal code and some additional notes on why I am doing this.

What's the expected result?

I expect my component to render.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-u2cja6?file=src%2Fpages%2Findex.astro&title=Astro%20Starter%20Kit:%20Basics

Participation

ematipico commented 3 days ago

By default, Astro uses the name of the componet to resolve it when rendering the island, but since you change the component to ComponentToRender, it's not able to find Card.astro anymore.

This is required by the Astro rendering engine.

Check the proposal for the internal requirements https://github.com/withastro/roadmap/blob/main/proposals/0050-server-islands.md#island-rendering

moonlitknight commented 3 days ago

That's fine. It might be worth including in the server islands documentation as it's reasonable for developers to expect that adding "server:defer" to a working component should not break it.

On Mon, 18 Nov 2024 at 14:56, Emanuele Stoppa @.***> wrote:

Closed #12458 https://github.com/withastro/astro/issues/12458 as not planned.

— Reply to this email directly, view it on GitHub https://github.com/withastro/astro/issues/12458#event-15334830322, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF4M266XZIMEG2PYAN3SZK32BHWYDAVCNFSM6AAAAABR567ZD2VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJVGMZTIOBTGAZTEMQ . You are receiving this because you authored the thread.Message ID: @.***>

ematipico commented 3 days ago

Thank you. I will bring this up with the team and see what's the best course of action

ematipico commented 3 days ago

What you might want to do is the following:

{
  ComponentToRender === 'Card' ? (
    <Card server:defer />
  ) : ComponentToRender === 'Other' ? (
    <Other server:defer />
  ) : ...
}

Astro relies on static analysis at the compiler level to determine the component to render. This is true for client directives too.