Skip to content

Commit

Permalink
perf: ⚡️ switched to Rc<ErrorPages> to avoid producing unnecessary …
Browse files Browse the repository at this point in the history
…`ErrorPages`
  • Loading branch information
arctic-hen7 committed Sep 8, 2021
1 parent 06b5fa4 commit 6786ff4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions examples/cli/.perseus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ pub fn run() -> Result<(), JsValue> {
// Create a mutable translations manager to control caching
let translations_manager =
Rc::new(RefCell::new(ClientTranslationsManager::new(&get_locales())));
// Get the error pages in an `Rc` so we aren't creating hundreds of them
let error_pages = Rc::new(get_error_pages());

sycamore::render_to(
|| {
template! {
BrowserRouter(move |route: AppRoute| {
// TODO improve performance rather than naively copying error pages for every template (use `Rc<ErrorPages>`)
match route {
// We handle the 404 for the user for convenience
AppRoute::NotFound => get_error_pages().get_template_for_page("", &404, "not found"),
Expand All @@ -44,7 +45,7 @@ pub fn run() -> Result<(), JsValue> {
locale,
// We give the app shell a translations manager and let it get the `Rc<Translator>` (because it can do async safely)
Rc::clone(&translations_manager),
get_error_pages()
Rc::clone(&error_pages)
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub fn app_shell(
// translator: Rc<Translator>,
locale: String,
translations_manager: Rc<RefCell<ClientTranslationsManager>>,
error_pages: ErrorPages,
error_pages: Rc<ErrorPages>,
) -> Template<DomNode> {
// Get the container as a DOM element
let container = NodeRef::new();
Expand Down

0 comments on commit 6786ff4

Please sign in to comment.