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
Cc/navigation prompts #1263
Cc/navigation prompts #1263
Conversation
2070ed2
to
d85d67d
Compare
d85d67d
to
336d094
Compare
Codecov Report
@@ Coverage Diff @@
## master #1263 +/- ##
==========================================
- Coverage 89.49% 89.48% -0.01%
==========================================
Files 219 220 +1
Lines 9164 9158 -6
Branches 1707 1704 -3
==========================================
- Hits 8201 8195 -6
Misses 850 850
Partials 113 113
Continue to review full report at Codecov.
|
return remove | ||
}, [onBeforeUnload, when, message]) | ||
|
||
return <ReactRouterPromp {...otherProps} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One consequence of using react-router's is that confirmation is now requested via window.confirm
, ie the browser's API. So the confirmation modal is now the browser's, not our customized version.
Update: I've customized this in the next PR toward #991. It will soon look like
"history": "^5.0.0", | ||
"history": "^4.10.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use react-router v5 which uses history v4 internally. We should be using history 4, too. remix-run/history#804 (comment)
This also solves some typescript issues we've had.
if (isLoading) { | ||
return <div className="site-page std-page-body container">Loading...</div> | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This early return was causing unnecessary component mount/unmounts lower in the component tree. For example:
-
Site is loaded,
<SiteContentListing />
renders -
click publish, new site api request is sent
Before: this
<div className="site-page std-page-body container">Loading...</div>
would replace the content listing, then a new content listing would be mounted after the API request is finished.Now: while the API request is in flight, the old content does not unmount (but a loading spinner shows atop it). When the API request finishes, the child component is updated (no unmount/remount, which was causing dirty form data to be lost).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM!
Pre-Flight checklist
What are the relevant tickets?
This is two of the three tasks in #991
What's this PR do?
This PR uses react-router's
<Prompt />
component to prompt users for confirmation when navigation would cause dirty form changes to be discarded. A few other things are included. See comments and "Background" below.How should this be manually tested?
docker-compose restart watch
to pickup changed frontend dependencies.Check closing the editing drawer:
beforeunload
event. We have less control over the warning in this case.)Note: The "prompt for confirmation" dialog has changed and is now the browser builtin "confirm" prompt.
Check that navigating away from unsaved changes elsewhere in the app prompts for confirmation. For example, on "Metadata", "Menus", or "Collaborators" pages
With a dirty "Metadata" form (or any other form for which the "Publish" button is still visible), click "Publish". The form changes should NOT be discarded.
There will be subsequent work to do something more informative here like alert user "Hey, do you really want to publish with some unsaved changes?". But with this PR, at least the changes are not lost.
Do any other navigation / form editing you feel like checking!
Any background context you want to provide?
On master we are only prompting users for dirty-form-discard-confirmation in two scenarios:
Ie, not when discarding dirty metadata / menu forms.
(1) happens via custom logic (the
<ConfirmationModal />
component and associateduseConfirmation
hook) and (2) happens viabeforeunload
browser events. Thebeforeunload
browser event is fired "when the window, the document and its resources are about to be unloaded."(mdn). So... not on navigation within the studio single-page app.This PR replaces our custom
<ConfirmationModal />
with React Router's<Prompt />
component. This change is enabled by the work Alice did tying editing to routes. Ie, before the editing drawer was tied to routes, we would not have been able to use , but now we can. So there's no need for a custom .