Skip to content

Commit 6786ff4

Browse files
committed
perf: ⚡️ switched to Rc<ErrorPages> to avoid producing unnecessary ErrorPages
1 parent 06b5fa4 commit 6786ff4

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

examples/cli/.perseus/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ pub fn run() -> Result<(), JsValue> {
2525
// Create a mutable translations manager to control caching
2626
let translations_manager =
2727
Rc::new(RefCell::new(ClientTranslationsManager::new(&get_locales())));
28+
// Get the error pages in an `Rc` so we aren't creating hundreds of them
29+
let error_pages = Rc::new(get_error_pages());
2830

2931
sycamore::render_to(
3032
|| {
3133
template! {
3234
BrowserRouter(move |route: AppRoute| {
33-
// TODO improve performance rather than naively copying error pages for every template (use `Rc<ErrorPages>`)
3435
match route {
3536
// We handle the 404 for the user for convenience
3637
AppRoute::NotFound => get_error_pages().get_template_for_page("", &404, "not found"),
@@ -44,7 +45,7 @@ pub fn run() -> Result<(), JsValue> {
4445
locale,
4546
// We give the app shell a translations manager and let it get the `Rc<Translator>` (because it can do async safely)
4647
Rc::clone(&translations_manager),
47-
get_error_pages()
48+
Rc::clone(&error_pages)
4849
)
4950
}
5051
}

packages/perseus/src/shell.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub fn app_shell(
115115
// translator: Rc<Translator>,
116116
locale: String,
117117
translations_manager: Rc<RefCell<ClientTranslationsManager>>,
118-
error_pages: ErrorPages,
118+
error_pages: Rc<ErrorPages>,
119119
) -> Template<DomNode> {
120120
// Get the container as a DOM element
121121
let container = NodeRef::new();

0 commit comments

Comments
 (0)