fix: preserve saved seed on page reload
The bug: Server-side page.tsx was ALWAYS generating a new seed with Date.now() on every page load, even when loading saved settings from the database. This caused different problems on every reload. The fix: - Check if saved config has a seed, use it if present - Only generate new seed if no saved seed exists (first visit) - Also preserve prngAlgorithm from saved config This ensures: - Reloading the page shows the same problems (from auto-saved seed) - Shared worksheets show same problems (from shared seed) - First-time visitors get a new random seed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -41,25 +41,31 @@ async function loadWorksheetSettings(): Promise<
|
||||
.limit(1)
|
||||
|
||||
if (!row) {
|
||||
// No saved settings, return defaults with a stable seed
|
||||
// No saved settings, return defaults with a new seed
|
||||
return {
|
||||
...defaultAdditionConfig,
|
||||
seed: Date.now() % 2147483647,
|
||||
prngAlgorithm: 'mulberry32',
|
||||
} as unknown as Omit<WorksheetFormState, 'date' | 'rows' | 'total'>
|
||||
}
|
||||
|
||||
// Parse and validate config (auto-migrates to latest version)
|
||||
const config = parseAdditionConfig(row.config)
|
||||
|
||||
// CRITICAL: Use saved seed if present, otherwise generate new one
|
||||
// This ensures reloading the page shows the same problems
|
||||
return {
|
||||
...config,
|
||||
seed: Date.now() % 2147483647,
|
||||
seed: (config as any).seed ?? Date.now() % 2147483647,
|
||||
prngAlgorithm: (config as any).prngAlgorithm ?? 'mulberry32',
|
||||
} as unknown as Omit<WorksheetFormState, 'date' | 'rows' | 'total'>
|
||||
} catch (error) {
|
||||
console.error('Failed to load worksheet settings:', error)
|
||||
// Return defaults on error with a stable seed
|
||||
// Return defaults on error with a new seed
|
||||
return {
|
||||
...defaultAdditionConfig,
|
||||
seed: Date.now() % 2147483647,
|
||||
prngAlgorithm: 'mulberry32',
|
||||
} as unknown as Omit<WorksheetFormState, 'date' | 'rows' | 'total'>
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user