Comments (4)
Thinking more I'm pretty sure the answer is to feature flag this so you default to serde
but can opt in to serde-lite
(or even miniserde
) with a flag.
from leptos.
Okay, this is pretty promising; it did manage to drop the bundle size of the HackerNews hydration client from 470kb to 445kb.
There are two concerns right now that are stopping me from just doing this:
- At the moment the
serde-lite
author doesn't haveSerialize
andDeserialize
implemented forResult
, so I moved all the HTTP requests over to return anOption<T>
. Given that I was returningResult<T, ()>
for simplicity there is no real difference, but in a real app this is a blocker. I've opened an issue onserde-lite
(see operutka/serde-lite#2) but would definitely want that resolved before I'd do this.
Maybe one of us could even submit a PR on serde-lite
for this.
- There are plenty of convenience crates that rely on
serde
to do things like JSON deserialization in fetch requests. The manual version withserde-lite
is a little more awkward, since you get text, then deserialize to an intermediate format, then deserialize to the actual type https://github.com/gbj/leptos/blob/5c022879f16d488ba7eca017a6aa42ad1474199a/examples/hackernews/hackernews-app/src/api.rs#L18-L27
Given the bundle size effects and the big benefit this would on load times have as apps scale up — I've found serde
to be the main culprit in real-app bundle sizes — I think this is worth it but would love some feedback.
Note: It would also be possible to feature-flag this, probably defaulting to serde
but giving a serde-lite
flag that allows you to opt-in to the smaller bundle sizes but deal with the quirks.
from leptos.
Oh and I should clarify: this is mostly to do with SSR + hydration mode, not pure-SPA client-side-rendering mode.
If you are doing SSR and hydrating resources/async requests will actually start on the server, and stream the results down to the client, which is much faster than waiting until the client has fully loaded. So initial load for the HackerNews demo is faster in SSR + hydrate mode than in SPA mode.
SPA/CSR mode:
- Ask server for HTML
- Browser sees it needs JS/WASM, and downloads them
- Once WASM is downloaded, run component, including the
create_resource
- Begin network request to fetch from API (from browser)
- Now we have data and can render it
SSR/hydrate mode:
- Ask server for HTML. Server has to render the page. While rendering page, sees the
create_resource
- Begins fetching from API (on server)
- Browser gets HTML. Sees it needs JS/WASM, and downloads them
- API request resolves on server and it streams the result down to the client. (If you're inside a
<Suspense/>
component it actually streams the newly-rendered HTML too and replaces the fallback state) - WASM is downloaded and runs the component.
- Sees the resource is already resolved, and deserializes it from JSON.
Depending on the API latency + WASM bundle size, streaming SSR means you often get the data + HTML before the WASM has even begun running, which is a huge speedup.
But this is why resource types need to be Serialize + Deserialize: so we can actually poll them on the server, send down JSON, and resolve them on the browser.
from leptos.
This was good for me to think aloud... I'm pretty happy with the solution in #33 and am going to go with that.
from leptos.
Related Issues (20)
- Derived signals can't be converted Into() Callbacks HOT 1
- Add a `Store` derive macro.
- Add ability to create an enumerated `<For />` component
- Notifying trigger in component breaks the trigger HOT 5
- Would it be useful to add a step, about installing 'Trunk' to the examples/README.md file HOT 2
- `create_resource` panics when server is compiled to wasm32-wasi HOT 8
- Using `<AnimatedRoutes/>` and `set_is_routing` in `<Router/>` together leads to Hydration Bugs HOT 3
- server functions are a bit restrictive HOT 2
- Deserialization error with multiple Suspense HOT 5
- Major drop in performance due to component nesting HOT 6
- Proposal: Better Server function redirect handling HOT 4
- Style display error when the style component specifies the ID HOT 2
- Passing the full url to `Form` omits the url entirely HOT 1
- Islands not working with workspace HOT 9
- module restructuring proposal HOT 3
- BorrowMut error when using signal immutably in `<Show/>` and mutably in `on:click`. HOT 7
- Need to pass context to server functions or use #[server] with struct methods HOT 2
- component annotation causes rust compiler to think generic has not been used HOT 8
- Compiler errors while running cargo make start on ./examples/tailwind_axum HOT 4
- Javascript no longer loads after page routing HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leptos.