withastro / astro

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

Implementing Custom Renderers triggers a misleading log message about the renderer not being recognized, while it actually is (and works) #12463

Open kyr0 opened 4 days ago

kyr0 commented 4 days ago

Astro Info

Astro                    v4.16.13
Node                     v23.2.0
System                   macOS (arm64)
Package Manager          npm
Output                   hybrid
Adapter                  @astrojs/cloudflare
Integrations             springtype

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

No response

Describe the Bug

Currently, when writing Astro integrations that use the addRenderer API of 'astro:config:setup', a quite misleading log message is printed with every re-render of any component that uses the custom renderer.

https://github.com/withastro/astro/blob/25baa4ed0c5f55fa85c2c7e2c15848937ed1dc9b/packages/astro/src/runtime/server/render/component.ts#L269

In my reproduction example you will find the log messages (after opening the console) despite the rendering working:

Bildschirmfoto 2024-11-18 um 03 44 02

This is, because the "recognized" renderers are hardcoded: https://github.com/withastro/astro/blob/25baa4ed0c5f55fa85c2c7e2c15848937ed1dc9b/packages/astro/src/runtime/server/render/component.ts#L35

The actual functionality however, works flawlessly, questioning the point of the log message warning.

Why is the log message misleading? When Astro welcomes third party developers to use the addRenderer API to add custom renderers, and custom renderers work well, both in SSR and client mode, because they are very well recognized by their custom name, then why would a log warning message like this make sense anymore?

I fixed this in the following PR: https://github.com/withastro/astro/pull/12461

Please don't be confused: In the reproduction example on CodeSandbox the issue still occurs because the dependency is pinned on the latest released astro version. When you check out my PR locally and run it with the command pnpm --filter @example/framework-custom run dev as developers are supposed to do, pnpm actually makes sure that my changed code with the fix is used and the misleading log message is already gone.

What's the expected result?

No warning log messages for custom renderers that clearly work and are recognized :)

Bildschirmfoto 2024-11-18 um 02 35 02

Link to Minimal Reproducible Example

https://codesandbox.io/p/devbox/github/kyr0/astro/tree/fix/custom-renderer-warning/examples/framework-custom

Participation

kyr0 commented 3 days ago

Note for people arriving late to the show (people from the future): Moved the example code for a custom renderer / custom frontend framework integration over here: https://github.com/kyr0/astro-custom-renderer