Open
Description
A child loader executes even though its parent loader returns a redirect (new NavigationResult({...})
). This leads to unexpected behavior where the child loader runs with undefined
data instead of being properly canceled or notified that the parent redirected.
Reproduction Steps
- Define a parent loader (
useParentEntityData
) that sometimes returns a redirect. - Define a child loader (
useChildEntityData
) that depends on data fromuseParentEntityData
. - Define a third-level loader (
useGrandchildEntityData
) that depends onuseChildEntityData
. - When
useParentEntityData
returns a redirect,useChildEntityData
still executes and receivesundefined
. useGrandchildEntityData
also executes, unknowingly usingundefined
fromuseChildEntityData
.- There is no indication that
useParentEntityData
returned a redirect, making it difficult to handle this scenario properly.
Expected Behavior
There are two possible expected behaviors depending on the approach taken:
Alternative 1: Automatic Child Loader Cancellation
- When a parent loader returns a redirect, all dependent child loaders should automatically not execute.
- This ensures that child loaders do not run with
undefined
values and removes the need for additional error handling. - However, this could limit flexibility if some child loaders need to execute even when a parent redirects.
Alternative 2: Explicit Redirect Metadata Propagation
- Child loaders should still execute but should be able to detect if a parent loader was canceled or redirected via explicit metadata.
- This metadata should be opt-in and propagated explicitly when defining loaders, allowing developers to control which loaders receive this information.
- This approach gives developers more control but requires them to handle redirects manually in child loaders.
Actual Behavior
- The child loader still executes and receives
undefined
, even though the parent loader redirected. - Dependent loaders further down the chain also execute, even though their ancestor loader was redirected.
- There is no mechanism for any of these loaders to detect that a parent redirected.
Possible Fixes
There are two possible solutions to address this issue:
Alternative 1: Automatically Cancel Child Loaders
- When a parent loader returns a redirect, all dependent child loaders should be automatically canceled.
- This would prevent child loaders from executing with
undefined
values and remove the need for additional error handling. - However, this approach may limit flexibility if some child loaders need to execute even when a parent redirects.
Alternative 2: Explicit Redirect Metadata Propagation
- Expose metadata in
DataLoaderContext
to indicate if a parent loader was canceled or redirected. - Ensure that this metadata is explicitly passed when defining child loaders, so developers can decide whether or not a loader should execute based on the redirect state.
- This approach gives developers more control but requires them to handle redirects manually in each child loader.
Metadata
Metadata
Assignees
Projects
Status
🆕 New