整合資料庫、完成登入註冊忘記密碼功能
This commit is contained in:
46
scripts/test-hydration-fix.js
Normal file
46
scripts/test-hydration-fix.js
Normal file
@@ -0,0 +1,46 @@
|
||||
async function testHydrationFix() {
|
||||
console.log('🧪 測試 Hydration 錯誤修復...\n');
|
||||
|
||||
try {
|
||||
// 測試管理員頁面載入
|
||||
console.log('1. 測試管理員頁面載入...');
|
||||
const response = await fetch('http://localhost:3000/admin');
|
||||
|
||||
if (response.ok) {
|
||||
console.log('✅ 管理員頁面載入成功');
|
||||
console.log('狀態碼:', response.status);
|
||||
|
||||
// 檢查頁面內容是否包含修復後的邏輯
|
||||
const pageContent = await response.text();
|
||||
|
||||
// 檢查是否包含客戶端狀態檢查
|
||||
if (pageContent.includes('isClient')) {
|
||||
console.log('✅ 客戶端狀態檢查已添加');
|
||||
} else {
|
||||
console.log('❌ 客戶端狀態檢查可能未生效');
|
||||
}
|
||||
|
||||
// 檢查是否移除了直接的 window 檢查
|
||||
if (!pageContent.includes('typeof window !== \'undefined\'')) {
|
||||
console.log('✅ 直接的 window 檢查已移除');
|
||||
} else {
|
||||
console.log('⚠️ 可能還有直接的 window 檢查');
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log('❌ 管理員頁面載入失敗:', response.status);
|
||||
}
|
||||
|
||||
console.log('\n🎉 Hydration 錯誤修復測試完成!');
|
||||
console.log('\n📋 修復內容:');
|
||||
console.log('✅ 添加了 isClient 狀態來處理客戶端渲染');
|
||||
console.log('✅ 移除了直接的 typeof window 檢查');
|
||||
console.log('✅ 使用 useEffect 確保客戶端狀態正確設置');
|
||||
console.log('✅ 防止服務器端和客戶端渲染不匹配');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 測試過程中發生錯誤:', error);
|
||||
}
|
||||
}
|
||||
|
||||
testHydrationFix();
|
Reference in New Issue
Block a user