Replies: 1 comment
-
2025-09-25.03-05-56.mp4Just to provide an example of what I'm trying to do, here is a quick demo I made when I tried asking in the discord. In the recording, I add 3 "Pokemon" components to my layout. I re-arrange the layout nodes and resize nodes. I also update the Pokemon that is selected in each component which updates a bindable prop (i.e. pokemonId). The layout and props are persisted to storage. When I refresh you will notice that the Pokemon IDs all reset because the props were not bound, while the rest of the layout persisted correctly. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I have a problem that I've spent the past week thinking about/working on that I cannot find a solution for. I've asked a few parts of this piecemeal in the Discord, but haven't gotten responses or a complete solution.
The problem
I have built a component layout manager library that deals with generic components. A simplified example of how I am handling components is as follows:
And rendered as
The problem I'm running into is the inability to support two way binding. My library supports persisting layouts, which provides unexpected results when bindable props aren't propagated back to the root layout structure.
Approach 1 (Unsupported)
The ideal approach to solving this problem is unsupported: Supporting the
bind:
directive for prop spreads. I've seen this discussion goes back years without much movement so I'm not expecting it to be a viable solution.On top of the lack of movement, the discussion I've seen also seems be lacking any way to selectively bind props - it's all or nothing. The proposals also seem to be mostly concerned with ergonomics, rather than enabling feature parity for generic components. Unlike with concrete components, this is no alternative to spreading with generic components.
Approach 2
The second approach is to bypass the svelte template syntax and use the imperative component API. The approach I've come it with for this is
Component<T>
typeinterface ComponentContainer<T extends Component<any> = Component<any>> { component: T; props: ComponentProps<T>; + bindings?: ComponentBindables<T>[]; }
bind:
behaviour by transforming each bound property into a{ get; set; }
pair.{ get; set; }
pairs as needed.I have tested, in the most basic case, that this approach can work. However I have some issues, some minor and some blockers:
mount
is basically inferior tohydrate
and doesn't really have a use. From that,render
should be called on the server and inserted into the component anchor with{@html ...}
. And thenhydrate
should be called on the client inside of the parent componentsonMount
callback.render()
it seems I can simply await itRenderOutput
may be incorrect, and also is not exportedhydrate()
I can't figure it out. When there is server rendered HTML inside of the anchor then hydrate will throw for async components.bind:
, despite being common from what I've gathered in other issues, is internal behaviour and not a publicly guaranteed contract that I would like to be depending onHave a missed a better approach? Or is this something that svelte just doesn't really support at the moment? Any help is appreciated.
I'm happy to provide more information or playground reproductions if it helps in any way.
Beta Was this translation helpful? Give feedback.
All reactions