Skip to content

Conversation

@david-crespo
Copy link
Collaborator

@david-crespo david-crespo commented Feb 24, 2024

Posting as a draft because this might be pointless. After getting rid of app/forms/index.ts, I saw that all the forms and fields were still being loaded on every page. After thinking about why this would be, I remembered that the routes file necessarily imports every page in the app, and that means that no matter what page you load, you have a dependency tree that ultimately points to every file used anywhere in the app.

So then I thought it might not be pointless if it helps with bundle splitting. I tested this theory by converting one form to a dynamic import.

diff showing how to convert a route to dynamic import
diff --git a/app/forms/ip-pool-create.tsx b/app/forms/ip-pool-create.tsx
index 94c761b9..8fc49a11 100644
--- a/app/forms/ip-pool-create.tsx
+++ b/app/forms/ip-pool-create.tsx
@@ -21,7 +21,7 @@ const defaultValues: IpPoolCreate = {
   description: '',
 }
 
-export function CreateIpPoolSideModalForm() {
+export function Component() {
   const navigate = useNavigate()
   const queryClient = useApiQueryClient()
 
diff --git a/app/routes.tsx b/app/routes.tsx
index fc2b73d0..bcc0749e 100644
--- a/app/routes.tsx
+++ b/app/routes.tsx
@@ -20,7 +20,6 @@ import {
 import { CreateImageFromSnapshotSideModalForm } from './forms/image-from-snapshot'
 import { CreateImageSideModalForm } from './forms/image-upload'
 import { CreateInstanceForm } from './forms/instance-create'
-import { CreateIpPoolSideModalForm } from './forms/ip-pool-create'
 import { EditIpPoolSideModalForm } from './forms/ip-pool-edit'
 import { IpPoolAddRangeSideModalForm } from './forms/ip-pool-range-add'
 import { CreateProjectSideModalForm } from './forms/project-create'
@@ -189,7 +188,7 @@ export const routes = createRoutesFromElements(
             handle={{ crumb: 'IP pools' }}
           >
             <Route path="ip-pools" element={null} />
-            <Route path="ip-pools-new" element={<CreateIpPoolSideModalForm />} />
+            <Route path="ip-pools-new" lazy={() => import('~/forms/ip-pool-create')} />
             <Route
               path="ip-pools/:pool/edit"
               element={<EditIpPoolSideModalForm />}

I then saw in the network tab that we were in fact no longer downloading app/forms/ip-pool-create.tsx on every page. But when I popped back to main and did the same thing, it had the same effect. That means getting rid of the app/forms barrel file was not necessary to achieve this effect, only the lazy import. Sad.

There's not really any downside to merging this since I already did the work and it's possible it will help with performance in other ways, for example by letting Vite be smarter about what files to hot reload.

@vercel
Copy link

vercel bot commented Feb 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
console ✅ Ready (Inspect) Visit Preview Feb 26, 2024 5:09pm

@david-crespo david-crespo marked this pull request as ready for review February 26, 2024 17:05
@david-crespo david-crespo merged commit bd64c62 into main Feb 26, 2024
@david-crespo david-crespo deleted the reduce-barrelage branch February 26, 2024 17:21
charliepark added a commit to oxidecomputer/omicron that referenced this pull request Feb 27, 2024
oxidecomputer/console@80f1167...e991ec5

* [e991ec5c](oxidecomputer/console@e991ec5c) oxidecomputer/console#1982
* [8e247f28](oxidecomputer/console@8e247f28) get rid of @oxide/gen alias
* [7d936d7e](oxidecomputer/console@7d936d7e) oxidecomputer/console#1981
* [b9a6051d](oxidecomputer/console@b9a6051d) delete unused app/table/headers
* [0b330247](oxidecomputer/console@0b330247) remove barrel files in app/pages
* [e53942ce](oxidecomputer/console@e53942ce) remove dot-path-fix vite plugin while we’re not using it
* [1af82bff](oxidecomputer/console@1af82bff) use vite-tsconfig-paths insead of my old manual thing
* [0f2411e8](oxidecomputer/console@0f2411e8) oxidecomputer/console#1962
* [bd64c620](oxidecomputer/console@bd64c620) oxidecomputer/console#1978
* [4388a92a](oxidecomputer/console@4388a92a) change pt-2 back to py-2 on AccordionItem
* [a0921bd6](oxidecomputer/console@a0921bd6) move msw handlers out of mock-api barrel file
* [6ab60b9b](oxidecomputer/console@6ab60b9b) update references to libs/ everywhere
* [9b4a6e0f](oxidecomputer/console@9b4a6e0f) move classed out of util barrel
* [d731de2b](oxidecomputer/console@d731de2b) oxidecomputer/console#1977
* [6c5883d9](oxidecomputer/console@6c5883d9) oxidecomputer/console#1976
* [6de56b15](oxidecomputer/console@6de56b15) oxidecomputer/console#1975
* [bbf019ee](oxidecomputer/console@bbf019ee) oxidecomputer/console#1973
* [b9c1892d](oxidecomputer/console@b9c1892d) oxidecomputer/console#1974
* [e2e56d87](oxidecomputer/console@e2e56d87) Revert `try .git-blame-ignore-revs`. don’t like it
* [1745a752](oxidecomputer/console@1745a752) try .git-blame-ignore-revs
* [4bfd2275](oxidecomputer/console@4bfd2275) oxidecomputer/console#1971
* [cb109cba](oxidecomputer/console@cb109cba) oxidecomputer/console#1968
* [264e2cd1](oxidecomputer/console@264e2cd1) oxidecomputer/console#1969
* [3ec255f9](oxidecomputer/console@3ec255f9) Revert `Shuffle @oxide/pagination files  (oxidecomputer/console#1970)`
* [3eebf491](oxidecomputer/console@3eebf491) oxidecomputer/console#1970
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants