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

Leptos 0.7 Support #44

Open
benwis opened this issue Sep 9, 2024 · 22 comments
Open

Leptos 0.7 Support #44

benwis opened this issue Sep 9, 2024 · 22 comments

Comments

@benwis
Copy link
Contributor

benwis commented Sep 9, 2024

Its getting close to release and we'll need to update this

@itowlson
Copy link
Collaborator

itowlson commented Oct 2, 2024

@benwis I'm trying to get this working and am currently stalled on server functions: calling register_explicit gives the error

error[E0271]: type mismatch resolving `<SaveCount as ServerFn>::ServerRequest == SpinRequest`
  --> src/server.rs:11:43
   |
11 |     crate::server_fn::register_explicit::<crate::app::SaveCount>();
   |                                           ^^^^^^^^^^^^^^^^^^^^^ expected `SpinRequest`, found `BrowserMockReq`
   |
note: required by a bound in `register_explicit`
  --> src/server_fn.rs:31:17

I think this is because the #[server] macro is falling through to https://github.com/leptos-rs/leptos/blob/e6da266b4f3fed5d4ebcabb2af5b7f2d3aebacd8/server_fn_macro/src/lib.rs#L545. (I don't think it's https://github.com/leptos-rs/leptos/blob/e6da266b4f3fed5d4ebcabb2af5b7f2d3aebacd8/server_fn_macro/src/lib.rs#L531 because the ssr feature is set on the dependency, but I could be wrong.)

It looks like the escape hatch for environments other than Axum or Actix is to provide types to the macro (req_ty or preset_req), but 1. I'm not sure how to do this and 2. I don't want to pass this on to application developers.

Do you know of a way to infer Spin request and response types that's transparent to users of the macro?

If not, is the only remedy to send a PR for Spin support directly into the server_fn crate?

@benwis
Copy link
Contributor Author

benwis commented Oct 13, 2024

@itowlson Sorry I missed this one, but passing SpinRequest and SpinResponse to the server macro is part of the leptos-spin-macro crate. Assuming you've imported that one and not the standard server, the other typical cause of this is feature flag issues, Once I'm back from Vienna for EuroRust I can take a deeper look

@ogghead
Copy link
Contributor

ogghead commented Oct 15, 2024

I would be interested in seeing this completed -- I have been dabbling in Leptos + Spin and am hoping to use some of the 0.7 components from the Thaw UI library. Let me know if I can help on this!

@benwis
Copy link
Contributor Author

benwis commented Oct 23, 2024 via email

@ogghead
Copy link
Contributor

ogghead commented Oct 24, 2024

Awesome! I went ahead and created #46 to upgrade to the latest version of 0.6 leptos :)

I will dig into the 0.7 upgrade tonight!

@ogghead
Copy link
Contributor

ogghead commented Oct 25, 2024

0.7 upgrade is certainly a bigger lift! I need to grok the Leptos server internals/how the 0.6 connection works/architectural changes made in 0.7. Then I can meaningfully contribute to this 0.7 update. I will dig into these learnings this weekend.

If @itowlson is further along with the 0.7 update, don't let me hold it up!

@itowlson
Copy link
Collaborator

@ogghead I'm currently away from the 0.7 update on other things - I did start looking but very quickly came up against the substantive API changes and got myself in a huge muddle. So if you see a way forward then please dive in! Thanks for all your work on this!

@ogghead
Copy link
Contributor

ogghead commented Oct 29, 2024

@ogghead I'm currently away from the 0.7 update on other things - I did start looking but very quickly came up against the substantive API changes and got myself in a huge muddle. So if you see a way forward then please dive in! Thanks for all your work on this!

No worries, sounds about like where I ended up 😂 I will take another crack at it with the rc1 version of 0.7

@ogghead
Copy link
Contributor

ogghead commented Nov 1, 2024

I have created a PR for a partial draft of 0.7 -- got most functions compiling but for about 1/3 of lib.rs. I will continue to dig into Leptos 0.7 code to look for a good upgrade path for remaining functionality, but if ya'll (especially @benwis as the resident Leptos expert) have any feedback, much appreciated! This is definitely a hacky draft with lots of clones and hastily created mappings to try to modify existing code as little as possible

@ogghead
Copy link
Contributor

ogghead commented Nov 2, 2024

I found https://github.com/leptos-rs/leptos_wasi and leptos-rs/leptos#3063 while sleuthing -- @benwis I wonder if we should consider holding off on making major refactors in the Spin integration and utilize this WASI integration after it stabilizes?

@raskyld
Copy link

raskyld commented Nov 2, 2024

Would gladly collaborate with any Spin folks out there to see if crates can interop ! :)

@ogghead
Copy link
Contributor

ogghead commented Nov 3, 2024

Would gladly collaborate with any Spin folks out there to see if crates can interop ! :)

Thanks for the offer @raskyld and for your work creating this general WASI integration in Leptos! I am going to dig into this today -- Spin supports running WASI-HTTP components so my hope is that it will just work with minimal modifications through the power of WASI

@itowlson
Copy link
Collaborator

itowlson commented Nov 3, 2024

Wow! Yes, that sure looks very close to the ground that leptos-spin covers! It would be great to have a common framework for this stuff inside the Leptos org. One possible concern is I'd be reluctant to force developers to write to the WASIp2 bindings right now (the p1 target has more mature support for using the familiar standard library). But that's not a blocker, because p2 will improve over time, and the benefits of having a common p2-based framework may outweigh the inconvenience. We'll have a better sense of it once we kick the tyres on some applications and get a feel for how they look.

Great find @ogghead and excited to collaborate @raskyld!

@ogghead
Copy link
Contributor

ogghead commented Nov 3, 2024

Good call @itowlson -- I created a prototype using wasip1 bindings for now.

With some slight tweaks to mesh the existing Spin leptos template with https://github.com/raskyld/leptos-wasmcloud setup, I got a Spin app technically running (the best kind). Can confirm the server fn button opens a Spin-provided wasi kv store and updates data server-side after client side interaction. This gets us 99% of the way there already it seems!

I am seeing one oddity where the static site is not replaced by the hydrated version and instead is duplicated, but created https://github.com/ogghead/leptos-wasi-test with current prototype Spin app -- once I am able to determine the source of this last bug and play around with the integration a bit more, I suspect we can cut all code and only need a template in the leptos-spin repository!

Very much appreciate feedback, and please do let me know if there are any pitfalls with this approach I have not considered. Tentatively, this integration appears to work almost seamlessly

@ogghead
Copy link
Contributor

ogghead commented Nov 4, 2024

Fixed that last issue -- it was a one line fix in the hydration portion for my demo. So, I can confirm this WASI integration works seamlessly with Spin apps!

We will need Leptos 0.7 rc1 released to get all necessary changes from tagged crate versions rather than git + local path references, but that should only require tweaks in cargo.toml. I will then transfer these changes back into the leptos-spin template and update the 0.7 PR to remove all the rest of the code and only include this template. I will jump on that as soon as rc1 version of Leptos is released 😄

@ogghead
Copy link
Contributor

ogghead commented Nov 4, 2024

Tentatively updated the template to a draft version pointing to git repositories directly -- this template works for me

@benwis
Copy link
Contributor Author

benwis commented Nov 4, 2024 via email

@itowlson
Copy link
Collaborator

itowlson commented Nov 4, 2024

This is very, very cool. Thank you so much @ogghead for jumping into this.

@raskyld
Copy link

raskyld commented Nov 5, 2024

I was waiting for rc1 as well to truly test end-to-end the integration crate and make necessary tweaks :D It just got released: https://github.com/leptos-rs/leptos/releases/tag/v0.7.0-rc1

I am really happy that the integration went seamlessly, my end goal breaking the work in two phases:

  • One for WASI standards,
  • One for wasmCloud specifics,

was exactly to enable different runtime vendors to collaborate on their mutual foundations 🎉

And in this specific case, you can truly say it was a virtuous cycle since I took inspiration from your work on this repository to build leptos_wasi 🤝

@ogghead
Copy link
Contributor

ogghead commented Nov 5, 2024

I created one small PR to update to rc1 for leptos_wasi and one small PR to allow (in rc2 or release version) using the Executor re-exported in the Leptos crate. I updated the Spin template to point to rc1 versions and (for now) my branch of leptos_wasi with those dependency updates and can confirm it still works as expected.

@raskyld huge props for creating leptos_wasi, and glad it was a virtuous cycle with the excellent work put into creating leptos-spin! If you have capacity to check my PR for leptos_wasi, that would be much appreciated

@raskyld
Copy link

raskyld commented Nov 5, 2024

I will check that tonight (in a few hours since I am EU based) anyway since I am now unblocked by the release of rc1!

@ogghead
Copy link
Contributor

ogghead commented Nov 26, 2024

With #48 merged, remaining steps are:

  • Wait for Leptos 0.7 full release
  • Update leptos_wasi dependencies after Leptos 0.7 full release and publish a 0.7 version of that crate
  • Update template dependencies in this repository after Leptos 0.7 full release and publishing of leptos_wasi 0.7 version
  • Publish new template in Spin (potentially?)

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

No branches or pull requests

4 participants