Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update compile.ts Deals with Hydration directive error #12078

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/astro/src/vite-plugin-astro/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ export async function compileAstro({

try {
transformResult = await compile(compileProps);

// Check for client: hydration directives in the compiled JSX structure
const hasHydrationDirective = transformResult.code.includes('client:');
if (hasHydrationDirective) {
// Optionally log a warning or error for devs
logger.warn(
null,
`Hydration directive found in ${compileProps.filename}. Astro components should not use client-side rendering.`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rn we show in what component an invalid client directive is found right? Is it also possible to show on what component it happens?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from my understanding the error is from the way the component is used. and the file that calls it incurrectly that is logged.

);
}

// Compile all TypeScript to JavaScript.
// Also, catches invalid JS/TS in the compiled output before returning.
esbuildResult = await transformWithEsbuild(transformResult.code, compileProps.filename, {
Expand Down
Loading