diff --git a/craft/src/state/PageContext.tsx b/craft/src/state/PageContext.tsx index 6353f12..38e7e32 100644 --- a/craft/src/state/PageContext.tsx +++ b/craft/src/state/PageContext.tsx @@ -383,25 +383,6 @@ export const PageProvider: React.FC<{ children: ReactNode }> = ({ children }) => return id; }; const rootId = walk(tree, null); - // DIAGNOSTIC: dump the produced state + scan for type=undefined nodes - // so when the resolver invariant fires we can see which node is bad. - try { - const w = window as any; - w.__sitesmithLastTree = tree; - w.__sitesmithLastState = nodes; - const bad: Array<{id:string; node:any}> = []; - for (const [nid, n] of Object.entries(nodes)) { - const t = (n as any).type; - const name = t && typeof t === 'object' ? t.resolvedName : t; - if (!name) bad.push({ id: nid, node: n }); - } - if (bad.length > 0) { - // eslint-disable-next-line no-console - console.warn('[SITESMITH] nodes with undefined type:', bad); - } - // eslint-disable-next-line no-console - console.log('[SITESMITH] treeToState produced', Object.keys(nodes).length, 'nodes; rootId=', rootId); - } catch (_e) { /* diagnostic only */ } // Craft.js deserialize requires the root node keyed as 'ROOT' if (rootId !== 'ROOT') { nodes['ROOT'] = nodes[rootId]; diff --git a/craft/src/utils/tiny-invariant-shim.ts b/craft/src/utils/tiny-invariant-shim.ts deleted file mode 100644 index 05becd8..0000000 --- a/craft/src/utils/tiny-invariant-shim.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Diagnostic shim for tiny-invariant. The prod tiny-invariant strips - * the failure message, so we lose the actual reason for any Craft.js - * Invariant. Aliasing tiny-invariant -> this shim restores it. - */ -/** - * Some Craft.js invariants are used as control-flow (try/catch wraps them - * to test a condition without explicit branching). Logging every one would - * drown out the actually-interesting failures. Suppress the well-known - * "is-it-X check" messages and log only the unfamiliar ones. - */ -const BENIGN = new Set([ - 'A top-level Node cannot be moved', - 'Cannot drag a non-canvas Node onto another Node', -]); - -export default function invariant(condition: unknown, message?: string | (() => string)): asserts condition { - if (condition) return; - const provided = typeof message === 'function' ? message() : message; - const value = provided ? `Invariant failed: ${provided}` : 'Invariant failed'; - if (!provided || !BENIGN.has(String(provided))) { - // eslint-disable-next-line no-console - console.error('[CRAFT INVARIANT]', value); - // eslint-disable-next-line no-console - console.error(new Error('stack-only').stack); - } - throw new Error(value); -} diff --git a/craft/vite.config.ts b/craft/vite.config.ts index d77c538..d35d5e4 100644 --- a/craft/vite.config.ts +++ b/craft/vite.config.ts @@ -8,9 +8,6 @@ export default defineConfig({ resolve: { alias: { '@': path.resolve(__dirname, './src'), - // Diagnostic: replace tiny-invariant with a shim that always logs the - // failure message (the upstream prod build strips it). - 'tiny-invariant': path.resolve(__dirname, './src/utils/tiny-invariant-shim.ts'), }, }, build: {