From db16c67f1a09c3f7b5c003378bc2f7f65cca4bb3 Mon Sep 17 00:00:00 2001 From: Evan Purkhiser Date: Wed, 29 Sep 2021 17:29:37 -0700 Subject: [PATCH] perf(js): Avoid rebuilding routes w/ memoization --- static/app/routes.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/static/app/routes.tsx b/static/app/routes.tsx index 3c00a3355e4d9e..b918a6ec97f706 100644 --- a/static/app/routes.tsx +++ b/static/app/routes.tsx @@ -7,6 +7,7 @@ import { Route as BaseRoute, RouteProps, } from 'react-router'; +import memoize from 'lodash/memoize'; import LazyLoad from 'app/components/lazyLoad'; import {EXPERIMENTAL_SPA} from 'app/constants'; @@ -59,7 +60,7 @@ const hook = (name: HookName) => HookStore.get(name).map(cb => cb()); const SafeLazyLoad = errorHandler(LazyLoad); -function routes() { +function buildRoutes() { // Read this to understand where to add new routes, how / why the routing // tree is structured the way it is, and how the lazy-loading / // code-splitting works for pages. @@ -1935,4 +1936,8 @@ function routes() { return appRoutes; } +// We load routes both when initlaizing the SDK (for routing integrations) and +// when the app renders Main. Memoize to avoid rebuilding the route tree. +const routes = memoize(buildRoutes); + export default routes;