-
Notifications
You must be signed in to change notification settings - Fork 1
perf: split lightweight state-index out of the registry (drop ~26KB from client routes) #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
| // Copyright (C) 2026 Steel-Tech / StructuPath | ||
| import { describe, it, expect } from "vitest"; | ||
| import { STATE_REGISTRY } from "@/content/state-registry"; | ||
| import { STATE_INDEX, STATE_LIST } from "@/content/state-index"; | ||
|
|
||
| // state-index.ts is GENERATED from the registry (scripts/gen-state-index.ts). | ||
| // These tests fail if it drifts — e.g. a state added to the registry without | ||
| // regenerating the index — so the lightweight client copy can't go stale. | ||
| describe("state-index sync with state-registry", () => { | ||
| it("covers exactly the same state codes", () => { | ||
| expect(Object.keys(STATE_INDEX).sort()).toEqual( | ||
| Object.keys(STATE_REGISTRY).sort(), | ||
| ); | ||
| }); | ||
|
|
||
| it("matches code/name/emoji for every state", () => { | ||
| for (const [code, data] of Object.entries(STATE_REGISTRY)) { | ||
| expect(STATE_INDEX[code]).toEqual({ | ||
| code: data.code, | ||
| name: data.name, | ||
| emoji: data.emoji, | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| it("STATE_LIST holds every state, sorted by name", () => { | ||
| expect(STATE_LIST).toHaveLength(Object.keys(STATE_REGISTRY).length); | ||
| const names = STATE_LIST.map((s) => s.name); | ||
| expect(names).toEqual([...names].sort((a, b) => a.localeCompare(b))); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
| // Copyright (C) 2026 Steel-Tech / StructuPath | ||
| // | ||
| // GENERATED from content/state-registry.ts — do not edit by hand. | ||
| // A lightweight {code, name, emoji} index for dropdowns and name/emoji display. | ||
| // Components that don't need full StateData import this instead of the registry, | ||
| // keeping the ~26KB registry data out of their client bundles. | ||
| // Regenerate: npx tsx scripts/gen-state-index.ts | ||
| // content/state-index.test.ts asserts this stays in sync with the registry. | ||
|
|
||
| export interface StateSummary { | ||
| code: string; | ||
| name: string; | ||
| emoji: string; | ||
| } | ||
|
|
||
| export const STATE_INDEX: Record<string, StateSummary> = { | ||
| AK: { code: "AK", name: "Alaska", emoji: "🐻" }, | ||
| AL: { code: "AL", name: "Alabama", emoji: "🏈" }, | ||
| AR: { code: "AR", name: "Arkansas", emoji: "💎" }, | ||
| AZ: { code: "AZ", name: "Arizona", emoji: "🌵" }, | ||
| CA: { code: "CA", name: "California", emoji: "🌴" }, | ||
| CO: { code: "CO", name: "Colorado", emoji: "⛰️" }, | ||
| CT: { code: "CT", name: "Connecticut", emoji: "🏛️" }, | ||
| DE: { code: "DE", name: "Delaware", emoji: "🦀" }, | ||
| FL: { code: "FL", name: "Florida", emoji: "🌞" }, | ||
| GA: { code: "GA", name: "Georgia", emoji: "🍑" }, | ||
| HI: { code: "HI", name: "Hawaii", emoji: "🌺" }, | ||
| IA: { code: "IA", name: "Iowa", emoji: "🌽" }, | ||
| ID: { code: "ID", name: "Idaho", emoji: "🥔" }, | ||
| IL: { code: "IL", name: "Illinois", emoji: "🏙️" }, | ||
| IN: { code: "IN", name: "Indiana", emoji: "🏎️" }, | ||
| KS: { code: "KS", name: "Kansas", emoji: "🌻" }, | ||
| KY: { code: "KY", name: "Kentucky", emoji: "🐴" }, | ||
| LA: { code: "LA", name: "Louisiana", emoji: "⚜️" }, | ||
| MA: { code: "MA", name: "Massachusetts", emoji: "🎓" }, | ||
| MD: { code: "MD", name: "Maryland", emoji: "🦀" }, | ||
| ME: { code: "ME", name: "Maine", emoji: "🦞" }, | ||
| MI: { code: "MI", name: "Michigan", emoji: "🏗️" }, | ||
| MN: { code: "MN", name: "Minnesota", emoji: "❄️" }, | ||
| MO: { code: "MO", name: "Missouri", emoji: "🏛️" }, | ||
| MS: { code: "MS", name: "Mississippi", emoji: "🎸" }, | ||
| MT: { code: "MT", name: "Montana", emoji: "🦌" }, | ||
| NC: { code: "NC", name: "North Carolina", emoji: "🏔️" }, | ||
| ND: { code: "ND", name: "North Dakota", emoji: "🦬" }, | ||
| NE: { code: "NE", name: "Nebraska", emoji: "🌾" }, | ||
| NH: { code: "NH", name: "New Hampshire", emoji: "🏔️" }, | ||
| NJ: { code: "NJ", name: "New Jersey", emoji: "🏖️" }, | ||
| NM: { code: "NM", name: "New Mexico", emoji: "🌶️" }, | ||
| NV: { code: "NV", name: "Nevada", emoji: "🎰" }, | ||
| NY: { code: "NY", name: "New York", emoji: "🗽" }, | ||
| OH: { code: "OH", name: "Ohio", emoji: "🏈" }, | ||
| OK: { code: "OK", name: "Oklahoma", emoji: "🌪️" }, | ||
| OR: { code: "OR", name: "Oregon", emoji: "🌲" }, | ||
| PA: { code: "PA", name: "Pennsylvania", emoji: "🔔" }, | ||
| RI: { code: "RI", name: "Rhode Island", emoji: "⛵" }, | ||
| SC: { code: "SC", name: "South Carolina", emoji: "🌴" }, | ||
| SD: { code: "SD", name: "South Dakota", emoji: "🏔️" }, | ||
| TN: { code: "TN", name: "Tennessee", emoji: "🎸" }, | ||
| TX: { code: "TX", name: "Texas", emoji: "🤠" }, | ||
| UT: { code: "UT", name: "Utah", emoji: "🏜️" }, | ||
| VA: { code: "VA", name: "Virginia", emoji: "🏛️" }, | ||
| VT: { code: "VT", name: "Vermont", emoji: "🍁" }, | ||
| WA: { code: "WA", name: "Washington", emoji: "🌲" }, | ||
| WI: { code: "WI", name: "Wisconsin", emoji: "🧀" }, | ||
| WV: { code: "WV", name: "West Virginia", emoji: "⛏️" }, | ||
| WY: { code: "WY", name: "Wyoming", emoji: "🤠" }, | ||
| }; | ||
|
|
||
| /** All states, sorted by name — for dropdowns. */ | ||
| export const STATE_LIST: StateSummary[] = Object.values(STATE_INDEX).sort( | ||
| (a, b) => a.name.localeCompare(b.name), | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
| // Copyright (C) 2026 Steel-Tech / StructuPath | ||
| // | ||
| // Generates content/state-index.ts — a standalone lightweight {code, name, | ||
| // emoji} index — from the full STATE_REGISTRY. Run: npx tsx scripts/gen-state-index.ts | ||
| import { writeFileSync } from "node:fs"; | ||
| import { STATE_REGISTRY } from "../content/state-registry"; | ||
|
|
||
| const entries = Object.values(STATE_REGISTRY) | ||
| .sort((a, b) => a.code.localeCompare(b.code)) | ||
| .map( | ||
| (s) => | ||
| ` ${s.code}: { code: ${JSON.stringify(s.code)}, name: ${JSON.stringify( | ||
| s.name, | ||
| )}, emoji: ${JSON.stringify(s.emoji)} },`, | ||
| ) | ||
| .join("\n"); | ||
|
|
||
| const out = `// SPDX-License-Identifier: AGPL-3.0-or-later | ||
| // Copyright (C) 2026 Steel-Tech / StructuPath | ||
| // | ||
| // GENERATED from content/state-registry.ts — do not edit by hand. | ||
| // A lightweight {code, name, emoji} index for dropdowns and name/emoji display. | ||
| // Components that don't need full StateData import this instead of the registry, | ||
| // keeping the ~26KB registry data out of their client bundles. | ||
| // Regenerate: npx tsx scripts/gen-state-index.ts | ||
| // content/state-index.test.ts asserts this stays in sync with the registry. | ||
|
|
||
| export interface StateSummary { | ||
| code: string; | ||
| name: string; | ||
| emoji: string; | ||
| } | ||
|
|
||
| export const STATE_INDEX: Record<string, StateSummary> = { | ||
| ${entries} | ||
| }; | ||
|
|
||
| /** All states, sorted by name — for dropdowns. */ | ||
| export const STATE_LIST: StateSummary[] = Object.values(STATE_INDEX).sort( | ||
| (a, b) => a.name.localeCompare(b.name), | ||
| ); | ||
| `; | ||
|
|
||
| writeFileSync(new URL("../content/state-index.ts", import.meta.url), out); | ||
| console.log( | ||
| `Wrote content/state-index.ts with ${Object.keys(STATE_REGISTRY).length} states`, | ||
| ); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the wizard client bundle, this new index import does not remove the full registry: the same component imports
getPhaseContentfrom@/content/phases, andcontent/phases.tsimportsSTATE_REGISTRYto generate phase content. Becauseapp/wizard/[phase]/[step]/page.tsxrenders this client component, the wizard flow still ships the registry despite this change; split the phase definitions/light metadata from the registry-backed generators before treating this route as lightweight.Useful? React with 👍 / 👎.