Skip to content

Conversation

@DJJones66
Copy link
Contributor

🔧 Bugfix: Resolve Page Cache Inconsistency on Navigation

📌 Summary

This PR addresses an issue where stale or incorrect layout state could persist across page transitions in the Unified Page Renderer, resulting in inconsistent or incorrect rendering of layouts and modules when navigating between pages.

🐞 Problem

  • On page change, previously committed layouts could bleed into the next page if currentLayouts was empty, causing stale or cross-page layout states to be applied incorrectly.
  • Additionally, the UnifiedPageRenderer component was not resetting internal state cleanly between page transitions, exacerbating the caching problem.

✅ Solution

  1. State Validation in LayoutEngine

    • Introduced a guard in LayoutEngine.tsx to prefer currentLayouts if it is empty and committedLayouts is not, preventing stale layouts from being reused.
    • Added an isEmptyLayouts() utility to check all breakpoints (mobile, tablet, desktop, wide, ultrawide) for emptiness.
  2. State Isolation in UnifiedPageRenderer

    • Assigned a key prop to the LayoutEngine using pageData.id || pageId || route to ensure reactive re-rendering of the layout engine when navigating to a new page.
  3. Stricter Reset in useUnifiedLayoutState

    • Improved resetLayouts() to:

      • Clear committedLayoutsRef and lastCommittedVersionRef.
      • Flush the layoutChangeManagerRef.
      • Clear the layoutCommitTracker.
    • This ensures full isolation of layout state per page.

🧪 Test Coverage

  • Manually verified page navigation across multiple routes to confirm:

    • No layout bleed-through between pages
    • LayoutEngine re-initialization on route change
    • Correct rendering of modules/layouts based on the new page

🗂️ Affected Files

  • LayoutEngine.tsx — Updated layout decision logic and helper
  • UnifiedPageRenderer.tsx — Added key to force component remount
  • useUnifiedLayoutState.ts — Hardened reset behavior

@DJJones66 DJJones66 merged commit 8135863 into main Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants