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

Bump leptos dependency to 0.5. #4

Closed
wants to merge 1 commit into from
Closed

Conversation

Emm
Copy link

@Emm Emm commented Sep 16, 2023

This adds support for leptos 0.5 rc1.

Note that Portal now needs ChildrenFn instead of Children. Everything else is unchanged except for the API change introduced by leptos-rs/leptos#918

src/portal.rs Outdated
somewhere near the root of the app";

#[derive(Clone)]
struct PortalCtx(StoredValue<Vec<(TypeId, RwSignal<Option<Children>>)>>);
struct PortalCtx(StoredValue<Vec<(TypeId, RwSignal<Option<ChildrenFn>>)>>);
Copy link
Contributor

Choose a reason for hiding this comment

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

This was a change intentionally made. It would be better if we can use Children instead of ChildrenFn. What's the reason we need ChildrenFn again?

Copy link
Author

Choose a reason for hiding this comment

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

It doesn't compile with Children, likely due to the changes in the ownership system, but I must admit I didn't investigate further.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, got it. So one of the reasons why we changed it to Children was because a lot of times, in custom components, we take in Children as a prop, and pass that onto the portal component. If we can retain that, that would be amazing

Copy link
Owner

Choose a reason for hiding this comment

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

Children can only be called once, because it's type alias is FnOnce() -> View, whereas ChildrenFn is Fn() -> View. This means that if you use Children, you can only ever call the children function exactly once. If you need children to render more than once, such as when moving into an Fn() for DynChild, then you must use ChildrenFn, because it lets you call the children

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we perhaps use FnOnce() + Clone then?

I remember having significant issues with using ChildrenFn instead of Children, which is why the change was made.

Alternatively, can we perhaps add an example / test for making a custom component on top of the portal so that we can make sure it compiles?

Copy link
Owner

Choose a reason for hiding this comment

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

I haven't yet reviewed the PR, but it should be possible to use Children without requiring Clone...that's what the Option<Children> is for...when the children changes, we can children.take() and then render the FnOnce() -> View.

@jquesada2016
Copy link
Owner

Thank you for making this PR! I really appreciate it. Could you please bump it to leptos rc2?

@Emm
Copy link
Author

Emm commented Sep 25, 2023

Thank you for making this PR! I really appreciate it. Could you please bump it to leptos rc2?

Will do

@rakshith-ravi
Copy link
Contributor

rakshith-ravi commented Sep 30, 2023

Hey. Now that leptos 0.5 stable is out, we can update the dependency I suppose?

Once that is done, @jquesada2016 would you happen to have the time to make a release?

@jquesada2016
Copy link
Owner

@rakshith-ravi yes of course! Now, I have two options. I am wanting to rewrite the components to use the slots API. So, I can either merge this PR and cut a new release, or wait for me to rewrite the components and then release. Which one sounds better?

@rakshith-ravi
Copy link
Contributor

I think we can make a release so that we at least have something to work with in the meantime, and then make another release once we're reworked the internals.

Also, I noticed that @maccesch has put up a PR upstream at leptos-rs/leptos#1820. An alternate idea would be to release what we have now, and then collaborate with him to get the Slots API version upstreamed, and then once that is released in upstream, we can depreciate this and point people to use the upstream version. What do you think?

@maccesch
Copy link

maccesch commented Oct 1, 2023

My approach is a little different. I really like how Solid does the Portal. There's no target or context needed. Just an optional mount prop which defaults to <body>. That will cover a lot of cases with less boilerplate. It also allows to teleport to outside of the app. But of course any input is welcome!

@rakshith-ravi
Copy link
Contributor

Just an optional mount prop which defaults to <body>.

Would that allow for multiple portals? Like nested-portals kinda stuff

leptos = { version = "0.5.0", features = ["csr"] }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we keep this to 0.5 instead of specifically using 0.5.0?

@rakshith-ravi
Copy link
Contributor

On second thought, I really don't know if anybody would even want something like that, so idk

@maccesch
Copy link

maccesch commented Oct 1, 2023

I haven't tried it but I don't see why not.

@Emm
Copy link
Author

Emm commented Oct 2, 2023

I have updated the branch to leptos 0.5 and restored Children in portal.rs (via take), though the code isn't very nice. I haven't tested If, but the portal doesn't show. I'm investigating the issue.

Looking at the code, though, there is something that escapes me... We are using StoreValue to wrap the vector, instead of RWSignal, which makes me wonder how PortalOutput is supposed to get notified of changes in that vector. Any insights about this @jquesada2016 ?

@Emm
Copy link
Author

Emm commented Oct 13, 2023

This definitely doesn't work with the Option trick. The best I can do is ChildrenFnMut instead of Children. This also seems to be the idiomatic code in this situation.

@rakshith-ravi
Copy link
Contributor

Why Mut?

@Emm
Copy link
Author

Emm commented Oct 17, 2023

@rakshith-ravi, that's less restrictive than ChildrenFn

@Emm
Copy link
Author

Emm commented Oct 22, 2023

So, I haven't tried with slots, but a ChildrenFn/ChildrenFnMut doesn't work at all, even on a simple example. I thought it was an issue with not running with the right owner, but feeding adding the PortalOutput's owner to the saved data and updating using with_owner in the PortalInput does not help. I'm going to close this PR, I may come back if I get a better understanding of the reactive ownership.

@Emm Emm closed this Oct 22, 2023
@rakshith-ravi
Copy link
Contributor

Looks like @maccesch's version of portal is merged upstream. (leptos-rs/leptos#1820)

Would that solve the problem for us?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants