Skip to content

[Bug]: Blocker Function type is misleading #12231

Open
@CJHorlebein

Description

@CJHorlebein

What version of React Router are you using?

6.27.0

Steps to Reproduce

  • Set up a BlockerFunction using react-router.
  • Within the function, attempt to access args.currentLocation, args.nextLocation, or args.historyAction.
  • Trigger navigation to an external site or close the browser tab.

Expected Behavior

The BlockerFunction currently expects args to always be provided based on its typing, so developers naturally assume it will be available. However, args is only provided when navigating within the app. Typing args as potentially undefined would allow users to avoid type errors and handle cases where args may not be provided, such as when navigating to an external site or closing the tab.

Actual Behavior

When navigating to an external site or closing the tab, the args object in BlockerFunction is undefined, resulting in runtime errors if properties like currentLocation, nextLocation, or historyAction are accessed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions