From cf56f2a38841ef7b6d31dc3e75df7c2aa9167eba Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Sun, 12 Jul 2026 13:30:17 -0700 Subject: [PATCH] refactor(builder): remove dead per-page headCode field (D9) PageData.headCode was never populated from anything but '' and never read anywhere -- the real, live concept is SiteDesign.headCode (set via the Code modal, wired into Preview/export in D8). Remove the dead field from the PageData interface and its ~7 hardcoded headCode: '' seeds/discards in PageContext.tsx (DEFAULT_PAGE, DEFAULT_HEADER, DEFAULT_FOOTER, the context default value, addPage, setPagesCraftState, replaceAllPages). Update the PageData literals in useWhpApi.save.test.ts to match the trimmed interface. Verified via grep that nothing reads page.headCode, and `npm run build` (strict tsc) is clean -- no live reader broke. Co-Authored-By: Claude Opus 4.8 (1M context) --- craft/src/hooks/useWhpApi.save.test.ts | 8 ++++---- craft/src/state/PageContext.tsx | 10 ++-------- craft/src/types/index.ts | 1 - 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/craft/src/hooks/useWhpApi.save.test.ts b/craft/src/hooks/useWhpApi.save.test.ts index d8447af..91cb1df 100644 --- a/craft/src/hooks/useWhpApi.save.test.ts +++ b/craft/src/hooks/useWhpApi.save.test.ts @@ -2,10 +2,10 @@ import { describe, test, expect } from 'vitest'; import { buildSavePayload } from './useWhpApi'; import { PageData } from '../types'; -const pageA: PageData = { id: 'home', name: 'Home', slug: 'index', craftState: 'STORED_HOME', headCode: '' }; -const pageB: PageData = { id: 'page_2', name: 'About', slug: 'about', craftState: 'STORED_ABOUT', headCode: '' }; -const headerPage: PageData = { id: '__header__', name: 'Header', slug: '__header__', craftState: 'STALE_HEADER', headCode: '' }; -const footerPage: PageData = { id: '__footer__', name: 'Footer', slug: '__footer__', craftState: 'STALE_FOOTER', headCode: '' }; +const pageA: PageData = { id: 'home', name: 'Home', slug: 'index', craftState: 'STORED_HOME' }; +const pageB: PageData = { id: 'page_2', name: 'About', slug: 'about', craftState: 'STORED_ABOUT' }; +const headerPage: PageData = { id: '__header__', name: 'Header', slug: '__header__', craftState: 'STALE_HEADER' }; +const footerPage: PageData = { id: '__footer__', name: 'Footer', slug: '__footer__', craftState: 'STALE_FOOTER' }; describe('buildSavePayload', () => { test('editing header: live serialize lands in header_craft_state, not in any page slot', () => { diff --git a/craft/src/state/PageContext.tsx b/craft/src/state/PageContext.tsx index 2393b77..d08893b 100644 --- a/craft/src/state/PageContext.tsx +++ b/craft/src/state/PageContext.tsx @@ -116,8 +116,8 @@ export const DEFAULT_HEADER_STATE = JSON.stringify({ const PageContext = createContext({ pages: [], - headerPage: { id: HEADER_ID, name: 'Header', slug: '__header__', craftState: null, headCode: '' }, - footerPage: { id: FOOTER_ID, name: 'Footer', slug: '__footer__', craftState: null, headCode: '' }, + headerPage: { id: HEADER_ID, name: 'Header', slug: '__header__', craftState: null }, + footerPage: { id: FOOTER_ID, name: 'Footer', slug: '__footer__', craftState: null }, activePageId: 'home', isEditingHeader: false, isEditingFooter: false, @@ -166,7 +166,6 @@ const DEFAULT_PAGE: PageData = { name: 'Home', slug: 'index', craftState: null, - headCode: '', }; const DEFAULT_HEADER: PageData = { @@ -174,7 +173,6 @@ const DEFAULT_HEADER: PageData = { name: 'Header', slug: '__header__', craftState: DEFAULT_HEADER_STATE, - headCode: '', }; const DEFAULT_FOOTER: PageData = { @@ -182,7 +180,6 @@ const DEFAULT_FOOTER: PageData = { name: 'Footer', slug: '__footer__', craftState: null, - headCode: '', }; export const PageProvider: React.FC<{ children: ReactNode }> = ({ children }) => { @@ -307,7 +304,6 @@ export const PageProvider: React.FC<{ children: ReactNode }> = ({ children }) => name, slug: uniqueSlug(requestedSlug, prev.map((p) => p.slug)), craftState: null, - headCode: '', }, ]); @@ -380,7 +376,6 @@ export const PageProvider: React.FC<{ children: ReactNode }> = ({ children }) => // ALWAYS the landing page → slug 'index' → file index.html. slug: i === 0 ? 'index' : p.slug, craftState: p.craftState, - headCode: '', }))); }, []); @@ -500,7 +495,6 @@ export const PageProvider: React.FC<{ children: ReactNode }> = ({ children }) => name: p.name, slug, craftState: treeToState(p.tree), - headCode: '', }; }); setPages(built); diff --git a/craft/src/types/index.ts b/craft/src/types/index.ts index fe9f334..9642967 100644 --- a/craft/src/types/index.ts +++ b/craft/src/types/index.ts @@ -16,7 +16,6 @@ export interface PageData { name: string; slug: string; craftState: string | null; - headCode: string; } export interface AssetData {