Skip to content

use-prompt - #998

Closed
benjaminleonard wants to merge 1 commit into
mainfrom
use-prompt
Closed

benjaminleonard wants to merge 1 commit into
mainfrom
use-prompt

Conversation

@benjaminleonard

Copy link
Copy Markdown
Contributor

Added in case it was an easy task – from remix-run/react-router#8139 (comment)

For whatever reason navigator.block is always undefined. Pushing for reference.

@vercel

vercel Bot commented Jun 29, 2022 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
console-ui-storybook ✅ Ready (Inspect) Visit Preview Jun 29, 2022 at 4:03PM (UTC)

@david-crespo

david-crespo commented Jul 6, 2022 •

Copy link
Copy Markdown
Collaborator

The reason this doesn't work is @remix-run/router, which is the new core of both RR and Remix, has its own history implementation instead of depending on the history library, and it does not have block in there.

https://github.com/remix-run/react-router/blob/8bae986/packages/router/history.ts#L587-L614

Compare to block in history:

https://github.com/remix-run/history/blob/3e9dab4/packages/history/index.ts#L812-L829

This might not be as big a problem for us as you might think, because our forms are almost all in modals. (The only ones that aren't are instance create and the settings ones.) That means instead of preventing navigation, we can hook in to the modal close callback and prevent modal close if the form is dirty. That should be pretty easy to do and wouldn't rely on anything in RR. However it would leave out the non-modal forms.

@benjaminleonard

Copy link
Copy Markdown
Contributor Author

Ok that sounds good as a temporary measure – hopefully we're not too far off prompt being reintegrated into the library. If in a few months if it hasn't been added, would we able able to patch history with the missing block function? I don't know how complicated that would be.

@david-crespo

Copy link
Copy Markdown
Collaborator

It's non-trivial but not ridiculous. This is most of it — the part where it uses the presence of blockers to block history push and pop:

https://github.com/remix-run/history/blob/3e9dab4/packages/history/index.ts#L385-L428

https://github.com/remix-run/history/blob/3e9dab4/packages/history/index.ts#L472-L491

I raised it on their Discord, so I'll see if the dev focusing on RR has anything to say about it before making any plans.

@david-crespo

Copy link
Copy Markdown
Collaborator

Gonna close this until we get an update.

@benjaminleonard
benjaminleonard deleted the use-prompt branch February 13, 2023 17:20

This branch was successfully deployed

1 active deployment
Preview — a4cd815e Deployed Jun 29, 2022 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent user from leaving page with incomplete form

2 participants