Make UI framework contexts available between islands #742
Replies: 7 comments 6 replies
-
The same behavior happens in Solid.js with Kobalte (as I mentioned in this issue withastro/issues/9412) |
Beta Was this translation helpful? Give feedback.
-
@danspratling I think you could rename the proposal to something like "Make UI framework contexts available between islands" |
Beta Was this translation helpful? Give feedback.
-
Is there any progress? I have the same problem. |
Beta Was this translation helpful? Give feedback.
-
when i read official solution regarding this problem, I'm shocked and i thought they were just kidding, slap my face and re read again. Im not dreaming. Just read it here: https://docs.astro.build/en/recipes/sharing-state-islands/ So what they suggesting is to rebuild all popular component library like material ui, etc ourself using nano store?? all of this component library was mostly built using usecontext, even many of them just suggesting to move from Astro: |
Beta Was this translation helpful? Give feedback.
-
Any API ideas? |
Beta Was this translation helpful? Give feedback.
-
If posted this in the discord, I think an API similar to this would offer a lot of flexibility.
|
Beta Was this translation helpful? Give feedback.
-
There are some other comments here that overlap a bit, but I think it's worth re-stating the issue: Despite the title, this has nothing to do with astro islands or sharing state across components (in astro parlance). This issue is more about astro template syntax and how it works in conjunction with the underlying integration renderer, which in the case of OP and me, is astro/react. Tabs is technically separate components as far as astro is concerned but as far as I'm concerned, it's just one: ---
import { Tabs } from 'whatever';
// Leads to errors because Tabs.List expects to be contained within Tabs.Root, etc.
---
<Tabs.Root>
<Tabs.List>
<Tabs.Trigger>Tab Title</Tabs.Trigger>
</Tabs.List>
<Tabs.Content>Tab Content</Tabs.Content>
</Tabs.Root> There just needs to be a way to tell astro render this fragment altogether as one thing. I think what people are actually after here is something like this: ---
import { Tabs } from 'whatever';
---
<RenderFragmentTogether>
<Tabs.Root>
<Tabs.List>
<Tabs.Trigger><slot name="label" /></Tabs.Trigger>
</Tabs.List>
<Tabs.Content><slot name="content" /></Tabs.Content>
</Tabs.Root>
</RenderFragmentTogether> Of course, that's still of very limited usefulness since obviously, you'd want to pass N label/content combos... but that's another issue, I guess. The prevailing suggestion of "create an astro wrapper" I think demonstrates the issue isn't well understood, and I'm hoping this provides some clarity. |
Beta Was this translation helpful? Give feedback.
-
Body
Summary
Most react based UI libraries (especially headless ones) make use of linked component nesting, where the child components rely on the parent components to exist. This does not work in astro, and the correct solution to use this kind of component are very limiting.
Previous discussion
Background & Motivation
Here's one example from RadixUI, and another from HeadlessUI.
In React this structure acts like slots in Astro
The proposed solution is to create a react component that wraps these react library.
However, this is an very limiting solution that does not provide the same level of customisation as provided by the original libraries.
Issues with this approach
^ That's a lot of unnecessary duplication for an arbitrary/one-off change, but far less important than being able to pass components as children (you could argue that this duplication would happen either way).
Goals
Benefits
Beta Was this translation helpful? Give feedback.
All reactions