remix-run / history

Manage session history with JavaScript
MIT License
8.28k stars 961 forks source link

[enhancement] expect `getUserConfirmation` to get an object from this first argument #879

Open fengxinming opened 3 years ago

fengxinming commented 3 years ago

version: 4.10.1

if I set a new prompt with history.block, the prompt would return a Promise or Object, then getUserConfirmation would not be called.

function confirmTransitionTo(location, action, getUserConfirmation, callback) {
    // TODO: If another transition starts while we're still confirming
    // the previous one, we may end up in a weird state. Figure out the
    // best way to handle this.
    if (prompt != null) {
      var result = typeof prompt === 'function' ? prompt(location, action) : prompt;

      if (typeof result === 'string') {
        if (typeof getUserConfirmation === 'function') {
          getUserConfirmation(result, callback);
        } else {
          process.env.NODE_ENV !== "production" ? warning(false, 'A history needs a getUserConfirmation function in order to use a prompt message') : void 0;
          callback(true);
        }
      } else {
        // Return false from a transition hook to cancel the transition.
        callback(result !== false);
      }
    } else {
      callback(true);
    }
  }