You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: added page state store caching, preloading, and memory management (#204)
* feat: added eviction to the pss
This should fix any memory blowouts (not leaks, just the storage of
every single page's state can get a bit heavy), which occasionally
occurred in development.
* chore: clarified a comment
* feat: created facility to support storage of document metadata in pss
* feat: prevented network requests for cached head/state
After a page is fetched as a subsequent load, it won't be fetched again
until the PSS fills up! This doesn't work with initial loads, since the
head is pre-interpolated (and I don't want to increase the bundle size
by doubling it up in a variable; reading from the HTML is unreliable
since JS will likely have already modified it).
* feat: added preloading infrastructure
This has involved making `RenderCtx` hold much more data in the browser,
like the error pages and render context, though this should make routing
much lighter.
* fix: fixed longstanding clones in app route system
Apparently, it's perfectly valid to pass the Sycamore scope through to
the Sycamore router, which means we an access everything we need from
the render context! (I reckon there'll be a performance improvement to
moving the render context into a dedicated system though, beyond
Sycamore's context.)
* refactor: removed unnecessary if clause in fetching example
I think this led to some confusion the other day, so it's clarified now.
Just that we don't need `G::IS_BROWSER` if we're target-gating as well.
* feat: created user-facing preload system
This includes a new `core/preload` example.
* chore: applied #212 fix to new `preload` example
* feat: added initially loaded page caching
This is achieved through an extra `<meta>` delimiter that denotes the
end of the `<head>`, which should be pretty reliable at getting what the
user intended.
* feat: added feature to control initial page caching
Advanced `<head>` manipulations *could* in rare cases lead to bugs, so
the user can turn this off if necessary, and it's documented in the FAQ section.
Copy file name to clipboardExpand all lines: docs/next/en-US/reference/faq.md
+4
Original file line number
Diff line number
Diff line change
@@ -38,3 +38,7 @@ Sycamore v0.8.0 has been released in beta to solve these problems and many other
38
38
These macros are simple proxies over the more longwinded `#[cfg(target_arch = "wasm32")]` and the negation of that, respectively. They can be easily applied to functions, `struct`s, and other 'block'-style items in Rust. However, you won't be able to apply them to statements (e.g. `call_my_function();`) , since Rust's [proc macro hygiene](https://github.com/rust-lang/rust/issues/54727) doesn't allow this yet. If you need to use stable Rust, you'll have to go with the longwinded versions in these places, or you could alternatively create a version of the functions you need to call for the desired platform, and then a dummy version for the other that doesn't do anything (effectively moving the target-gating upstream).
39
39
40
40
The best solution, however, is to switch to nightly Rust (`rustup override set nightly`) and then add `#![feature(proc_macro_hygiene)]` to the top of your `main.rs`, which should fix this.
41
+
42
+
## I'm getting really weird errors with a page's `<head>`...
43
+
44
+
Alright, this can mean about a million things. There is one that could be known to be Perseus' fault though: if you go to a page in your app, then reload it, then go to another page, and then navigate *back* to the original page (using a link inside your app, *not* your browser's back button), and there are problems with the `<head>` that weren't there before, then you should disable the `cache-initial-load` feature on Perseus, since Perseus is having problems figuring out how your `<head>` works. Typically, a delimiter `<meta itemprop="__perseus_head_end">` is added to the end of the `<head>`, but if you're using a plugin that's adding anything essential after this, that will be lost on transition to the new page. Any advanced manipulation of the `<head>` at runtime could also cause this. Note that disabling this feature (which is on by default) will prevent caching of the first page the user loads, and it will have to be re-requested if they go back to it, which incurs the penalty of a network request.
This example demonstrates Perseus' inbuilt imperative preloading functionality, which allows downloading all the assets needed to render a page ahead-of-time, so that, when the user reaches that page, they can go to it without any network requests being needed!
// The render context will automatically handle prioritizing frozen or active state for us for this page as long as we have a reactive state type, which we do!
243
246
match render_ctx.get_active_or_frozen_page_state::<#rx_props_ty>(&props.path){
247
+
// If we navigated back to this page, and it's still in the PSS, the given state will be a dummy, but we don't need to worry because it's never checked if this evaluates
// The render context will automatically handle prioritizing frozen or active state for us for this page as long as we have a reactive state type, which we do!
288
292
match render_ctx.get_active_or_frozen_page_state::<#rx_props_ty>(&props.path){
293
+
// If we navigated back to this page, and it's still in the PSS, the given state will be a dummy, but we don't need to worry because it's never checked if this evaluates
# This feature adds support for a number of macros that will make your life MUCH easier (read: use this unless you have very specific needs or are completely insane)
# This feature enables caching of pages that are loaded through the initial loads system (i.e. the first one the user goes to on your site); this involves making a
67
+
# (usually excellent) guess at the contents of the `<head>` on that page. If you perform any advanced manipulation of the `<head>` such that loading a page from
68
+
# scratch, going somewhere else, and then going back to it breaks something, disable this.
69
+
cache-initial-load = []
66
70
# This feature enables Sycamore hydration by default (Sycamore hydration feature is always activated though)
67
71
# This is not enabled by default due to some remaining bugs (also, default features in Perseus can't be disabled without altering `.perseus/`)
0 commit comments