Skip to content

Ideas for improvements #247

@qknight

Description

@qknight

I'm trying to port my app from client side rendering CSR into server side rendering SSR with the help of this repository.

The documentation in https://book.leptos.dev/ssr/index.html is fairly limited, for instance:

Image

(as outlined with the red error, move this text down) and extend this text:

Leptos is one of a number of modern frameworks that introduce the concept of server functions. Server side rendering (SSR) is archived with a combination of a server function and a leptos component using it.

Concepts to teach

Using SSR means that we still work on a GET request basis (like in PHP) so we can't use signals the way we can in CSR mode. SSR still supports the concept of signals, but they are on a 'per-request-basis' and have a rather short time-span to live.

You can use leptos with CSR without accessing remote resources this way you can store data in the localStore of your browser. If you want to access remote data from a server in CSR, these are your options:

  • you access a REST interface, like a JSON API
  • you can use Websockets

Leptos with SSR offers these concepts:

Create new example from examples

I'm coming from leptos CSR with server data coming via REST. The leptos SSR concepts are new for me and I am used to:

  • passing huge amounts of RwSignals/Signals down different routes (they embody the global state of the application and can be updated using calls to external REST) - SSR would use a database for global state and WS for server push.
  • I use <Router><Routes fallback=|| "Not found."> ... but leptos SSR requires a rewrite into rust functions.

But reading https://github.com/leptos-rs/leptos/blob/main/examples/websocket confuses me greatly:

  • Having main.rs, lib.rs and websocket.rs with all the different entry points
  • The SSR router works differently than CSR

Extending the book

The book should be a continuous story of small extensions to the template starting with https://github.com/leptos-rs/start-axum-workspace and then:

  1. create a router 2 "/" (home) and "/todos"
  2. extend it with a function fn gen_content_from_server() which is running on the server only and called from a component on the UI
  3. extend the server core routine with a context, for server variables and then use that in fn gen_content_from_server()
  4. create a function which is only evaluated on the client
  5. extend the server with a db like sqlite and extend fn gen_content_from_server() to get data from the db
  6. create fn my_editor_component which loads and saves data from a fn on the server but uses a client side only editor
  7. extend server and client with a websocket and have a todo list which always updates all devices in sync

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions