Skip to content
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

Incompatible invocation of BlockerFunction #104

Closed
jacquesg opened this issue Jun 21, 2023 · 3 comments
Closed

Incompatible invocation of BlockerFunction #104

jacquesg opened this issue Jun 21, 2023 · 3 comments
Labels

Comments

@jacquesg
Copy link
Contributor

As part of 6a1dc67a20c14c3d5952f8252519ada413c82eb6 the following change has been introduced:

        if (
          (typeof when === "boolean" && when === true) ||
          // @ts-ignore Reload case -- No location present
          (typeof when === "function" && when())
        ) {

Calling when without any arguments is not compatible with

  export declare type BlockerFunction = (args: {
    currentLocation: Location;
    nextLocation: Location;
    historyAction: HistoryAction;
}) => boolean;

Currently, this manifests as the following on page reload for me:

formactionbuttonblock.tsx:60 Uncaught TypeError: Cannot destructure property 'nextLocation' of 'undefined' as it is undefined.
    at when (:3000/src/components/formactionbuttonblock.tsx:32:21)
    at :3000/node_modules/.vite/deps/react-router-prompt.js?v=d73664e4:644:35
@bilalkosker
Copy link

bilalkosker commented Oct 3, 2024

I solved the problem by adding in use-prompt.ts
const location = useLocation();
const action = useNavigationType();

then I updated use callback lines

(typeof when === "boolean" && when) || (typeof when === "function" && when({ currentLocation: location as Location<any>, nextLocation: blocker.location as Location<any>, historyAction: action }))
Then it works.

@CJHorlebein
Copy link

Hmmm I had a similar issue. It looks like this issue is mostly when you navigate outside of your app. This also doesn't look like an issue from this package since BlockerFunction is a dependency in react-router.

I made a issue in that repository here
remix-run/react-router#12231

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants