- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.3k
 
Merge __beforeLoadContext for pending loading state #5701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge __beforeLoadContext for pending loading state #5701
Conversation
          
WalkthroughThis PR introduces isolated context handling for beforeLoad execution and adds test coverage for preload context scenarios. It modifies the context propagation logic to ensure beforeLoad receives fresh context on each invocation, while the pending component state preserves prior context from successful matches. Changes
 Sequence DiagramsequenceDiagram
    participant App
    participant Router
    participant LoadMatches
    participant BeforeLoad
    participant Component
    App->>Router: Focus (preload)
    Router->>LoadMatches: Load with preload flag
    LoadMatches->>BeforeLoad: Call with beforeLoadFnInputContext (fresh)
    Note over BeforeLoad: Pending state marked<br/>with pendingContext<br/>(preserves prior context<br/>if match succeeded)
    
    App->>Router: Navigate (enter)
    Router->>LoadMatches: Load with enter flag
    LoadMatches->>BeforeLoad: Call with beforeLoadFnInputContext (fresh, not stale)
    Note over BeforeLoad: ✓ Fresh context,<br/>not preloaded context
    BeforeLoad-->>LoadMatches: beforeLoad resolves
    LoadMatches->>Component: Render with updated context
    Note over Component: __beforeLoadContext<br/>merged after beforeLoad<br/>completes
    Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 
 Possibly related issues
 Possibly related PRs
 Suggested reviewers
 Poem
 Pre-merge checks and finishing touches❌ Failed checks (1 warning)
 ✅ Passed checks (2 passed)
 ✨ Finishing touches
 🧪 Generate unit tests (beta)
 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
 🧰 Additional context used📓 Path-based instructions (3)**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md) 
 Files: 
 packages/router-core/**📄 CodeRabbit inference engine (AGENTS.md) 
 Files: 
 packages/{react-router,solid-router}/**📄 CodeRabbit inference engine (AGENTS.md) 
 Files: 
 🧠 Learnings (3)📚 Learning: 2025-09-23T17:36:12.598ZApplied to files: 
 📚 Learning: 2025-10-08T08:11:47.088ZApplied to files: 
 📚 Learning: 2025-09-23T17:36:12.598ZApplied to files: 
 🧬 Code graph analysis (1)packages/react-router/tests/routeContext.test.tsx (1)
 ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
 🔇 Additional comments (2)
 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment   | 
    
| 
           View your CI Pipeline Execution ↗ for commit 393b524 
 ☁️ Nx Cloud last updated this comment at   | 
    
| 
           @coderabbitai generate docstrings  | 
    
          
✅ Actions performedInitiated docstring generation; will generate only if new commits exist.  | 
    
| 
           Caution Docstrings generation - FAILED No docstrings were generated.  | 
    
| 
           Actually, this still doesn't fully solve the problem. The problem is that my component depends on context to such a degree that it cannot render at all until beforeLoad runs, and it seems that setting pendingComponent forces it to render to trigger suspense. This is gonna need some more work to figure out 🤔  | 
    
Based off of #5002, this takes it a step further and only merges context from previous load (when preloaded is successful) and send that to the component. This ensures the context maintains it's proper type even when pending.
fixes #4998
Summary by CodeRabbit
Bug Fixes
Tests