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

Fragment + nested client:only components + slots problem #9996

Closed
1 task
comus opened this issue Feb 6, 2024 · 1 comment · Fixed by #10316
Closed
1 task

Fragment + nested client:only components + slots problem #9996

comus opened this issue Feb 6, 2024 · 1 comment · Fixed by #10316
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@comus
Copy link

comus commented Feb 6, 2024

Astro Info

Astro                    v4.3.2
Node                     v18.18.0
System                   macOS (arm64)
Package Manager          npm
Output                   hybrid
Adapter                  @astrojs/vercel/serverless
Integrations             @astrojs/tailwind
                         @astrojs/react
                         simple-stream

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

No response

Describe the Bug

below is the "not working" case, which is webpage display nothing.

---
import { Hello, Island, World } from "@components/demo.tsx";
---

<Island client:only>
  <Fragment slot="footer"><Hello client:only /></Fragment>
  <Fragment slot="header"><World client:only /></Fragment>
</Island>

but, if don't use Fragment, it works

<Island client:only>
  <a slot="footer"><Hello client:only /></a>
  <a slot="header"><World client:only /></a>
</Island>

also, below is work if nested components not defined client:only

<Island client:only>
  <Fragment slot="footer"><Hello /></Fragment>
  <Fragment slot="header"><World /></Fragment>
</Island>

What's the expected result?

I expected this should work

<Island client:only>
  <Fragment slot="footer"><Hello client:only /></Fragment>
  <Fragment slot="header"><World client:only /></Fragment>
</Island>

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-qczw9r-srdto2?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Feb 6, 2024
@lilnasy lilnasy added - P4: important Violate documented behavior or significantly impacts performance (priority) and removed needs triage Issue needs to be triaged labels Feb 9, 2024
@Kanha-Dehury-01
Copy link

Nesting client:only directives can cause issues with rendering components on the server. Since the Island component is marked with client:only, any nested components with the same directive will also be skipped during server-side rendering. This can lead to empty content being displayed initially before the browser hydrates the components.

Instead of applying client:only to the Island component, move it to the individual components to render conditionally. This approach ensures that only the Hello and World components are skipped during server-side rendering, while the Island component itself is still rendered on the server.

<Island>
  <Fragment slot="footer"><Hello client:only /></Fragment>
  <Fragment slot="header"><World client:only /></Fragment>
</Island>

We can also use react-hydration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants