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

Support for Promise in beforeUrlChange #422

Open
www-chique opened this issue Jan 8, 2022 · 4 comments
Open

Support for Promise in beforeUrlChange #422

www-chique opened this issue Jan 8, 2022 · 4 comments
Labels
enhancement New feature or request needs triage v2

Comments

@www-chique
Copy link

I would love to have support for Promise in $beforeUrlChange.

Currently, in a "form", I look if the form has some changes, and if yes, I show a dialog which returns a promise, that resolves after user's choice of whether to discard the change.
It's pretty neat to wait for that response before I can return the $beforeUrlChange a "true" or "false".

Surprisingly, I am already using an asynchronous function there, but it pops out an incorrect type warning.
I am not sure whether it's merely a fix for the types or actually needs to support in the codebase.

image

I am happy to provide more details as needed.

@www-chique www-chique added enhancement New feature or request needs triage labels Jan 8, 2022
@jakobrosenberg
Copy link
Member

I thought this was already supported.

Are you using R2 or R3?

@www-chique
Copy link
Author

I am with R2, version 2.15.1.
If you ignore VSCode complaining about the type error, it actually works just fine.

-- Here is a sidenote: Routify is amazingly awesome. Thanks to you, Ghost and everyone else involved in the community for active support and amazing ideas.

@ghostdevv
Copy link
Member

ghostdevv commented Jan 13, 2022

Can be fixed in this line I imagine @jakobrosenberg -

* @param {(event?: PopStateEvent, route?: ClientNodeApi) => boolean} callback

If this is valid jsdoc then it's as simple as:

(event?: PopStateEvent, route?: ClientNodeApi) => boolean} to
(event?: PopStateEvent, route?: ClientNodeApi) => boolean | Promise<boolean>}

@jakobrosenberg
Copy link
Member

I have found the issue behind this. The types are automatically generated on build, but the type for beforeUrlChange was added manually in the generated definition file.

I'll try to sort this when I get home.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage v2
Projects
None yet
Development

No branches or pull requests

3 participants