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

Ability to execute async code when rendering in SSR mode #597

Open
evertedsphere opened this issue Apr 6, 2023 · 0 comments
Open

Ability to execute async code when rendering in SSR mode #597

evertedsphere opened this issue Apr 6, 2023 · 0 comments
Labels
A-SSR Area: Server Side Rendering (SSR) and Static Site Generation (SSG)

Comments

@evertedsphere
Copy link

evertedsphere commented Apr 6, 2023

I'm building a Sycamore app (it's been great so far), and I have a backend server that provides an API, as well as serves the SSR version of the site which is then hydrated in the browser.

Most of the content on each page is fetched at runtime in the client via a spawn_local_scoped call that does a network request to the API (which does a couple async DB queries with sqlx and produces the data). However, this data is nearly all static, so I'd like to render it on the server if possible. This would be entirely doable if there were a way of either

  1. directly running my async get_item_by_id function within the view at SSR time (faster)
  2. doing a network call to the API at SSR time (lets me reuse my existing client API interaction code)

Either of these is easy to do if I have access to the async context that Sycamore seems to run render_to_string in. Without it, a naked spawn_local_scoped crashes without access to a LocalSet, but I can't create a Tokio runtime myself either because we're already within one somehow (and provide_executor_scope is useless without some way to await on the future it returns).

@lukechu10 lukechu10 added the A-SSR Area: Server Side Rendering (SSR) and Static Site Generation (SSG) label Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-SSR Area: Server Side Rendering (SSR) and Static Site Generation (SSG)
Projects
None yet
Development

No branches or pull requests

2 participants