Skip to content

Commit 92deae6

Browse files
committed
fix: increase load time to avoid hydration errors while DOM loads
1 parent 2e04630 commit 92deae6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/js/details-clicks.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,22 @@ const preserveExpansionStates = ExecutionEnvironment.canUseDOM ? function(skipEv
564564
return setTimeout(preserveExpansionStates, 100);
565565
}
566566

567+
// Wait for React hydration to complete on initial page load with hash
568+
// Check if React has hydrated by looking for React internal properties
569+
if (!skipEventListener && location.hash && !window.__hydrationComplete) {
570+
const rootElement = document.getElementById('__docusaurus');
571+
// Check if React has attached its fiber root (sign of hydration completion)
572+
const isHydrated = rootElement && (rootElement._reactRootContainer || rootElement._reactRootContainer === null || Object.keys(rootElement).some(key => key.startsWith('__react')));
573+
574+
if (!isHydrated) {
575+
return setTimeout(preserveExpansionStates, 100);
576+
}
577+
578+
// Extra safety delay after hydration detected
579+
window.__hydrationComplete = true;
580+
return setTimeout(preserveExpansionStates, 50);
581+
}
582+
567583
// Add copy buttons to config fields
568584
addCopyButtons();
569585

0 commit comments

Comments
 (0)