Files
soroban-abacus-flashcards/test-templates-integration.js
Thomas Hallock bda5bc6c0e fix: prevent database imports from being bundled into client code
**Problem:**
- player-ownership.ts imported drizzle-orm and @/db at top level
- When RoomMemoryPairsProvider imported client-safe utilities, Webpack bundled ALL imports including database code
- This caused hydration error: "The 'original' argument must be of type Function"
- Node.js util.promisify was being called in browser context

**Solution:**
1. Created player-ownership.client.ts with ONLY client-safe utilities
   - No database imports
   - Safe to import from 'use client' components
   - Contains: buildPlayerOwnershipFromRoomData(), buildPlayerMetadata(), helper functions

2. Updated player-ownership.ts to re-export client utilities and add server-only functions
   - Re-exports everything from .client.ts
   - Adds buildPlayerOwnershipMap() (async, database-backed)
   - Safe to import from server components/API routes

3. Updated RoomMemoryPairsProvider to import from .client.ts

**Result:**
- No more hydration errors on /arcade/room
- Client bundle doesn't include database code
- Server code can still use both client and server utilities

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-10 11:40:46 -05:00

45 lines
1.4 KiB
JavaScript

#!/usr/bin/env node
// Test template integration from web app context
console.log("🌐 Testing web app template integration\n");
// Test the web app's current imports
try {
// Simulate the current web app API route import
const { FLASHCARDS_TEMPLATE } = require("@soroban/templates");
console.log("✅ Web app import successful:");
console.log(" Path:", FLASHCARDS_TEMPLATE);
// Test file system access
const fs = require("fs");
const exists = fs.existsSync(FLASHCARDS_TEMPLATE);
console.log(" File accessible:", exists);
if (exists) {
const content = fs.readFileSync(FLASHCARDS_TEMPLATE, "utf-8");
console.log(" Content length:", content.length + " chars");
console.log(" Content preview:", content.substring(0, 100) + "...");
}
} catch (error) {
console.log("❌ Web app import failed:", error.message);
}
console.log("\n🧮 Testing what the current web app files expect:\n");
// Test the exact same pattern used in the web app files
try {
const templatesPackage = require("@soroban/templates");
console.log("✅ Package structure:");
console.log(" Available exports:", Object.keys(templatesPackage));
console.log(
" FLASHCARDS_TEMPLATE type:",
typeof templatesPackage.FLASHCARDS_TEMPLATE,
);
console.log(
" SINGLE_CARD_TEMPLATE type:",
typeof templatesPackage.SINGLE_CARD_TEMPLATE,
);
} catch (error) {
console.log("❌ Package import failed:", error.message);
}