Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Right now, Perseus renders all user pages under the single, global
cx
scope, which is used for the entire app. This works well, until you use something like the router state (a global entity) and log every time there's a page change. I tried this in my rebuild of my own blog, and found very quickly that the logs were accumulating: the listeners were not being killed when I was navigating off the page. In other words, all listeners on global events were accumulating in Perseus apps. This may have been the cause of the error I occasionally observed while working on the Perseus website for long stretches, whereby my browser would freeze up after a few hours until I killed the tab. I now believe that may have been due to listener accumulations and improper memory clearing.This PR adds a
RouteManager
struct
to Perseus, which bundles together aSignal
registered on the app scope for storing the currentView<G>
with aScopeDisposer
for the current view's scope. All user pages are rendered in a child scope (created by the#[template]
macro, for now), and, when a new page is rendered, the old view is replaced, and the old scope disposer is disposed of. This introduces a single line ofunsafe
to the Perseus core, with safety clearly enforced by the macros. (Users who avoid#[template]
should be cautious not to dispose of a scope inside that scope, which is pretty much common sense, and very clearly documented.) This entirely prevents the issues explained above.