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

Autosave: trigger autosave regardless of being idle #12839

Merged
merged 5 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 4 additions & 7 deletions packages/story-editor/src/components/autoSaveHandler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@ function AutoSaveHandler() {
const {
state: { hasNewChanges },
} = useHistory();
const { autoSave } = useStory(({ actions }) => ({
const { autoSave, isSaving } = useStory(({ actions, state }) => ({
isSaving: state.meta.isSaving,
autoSave: actions.autoSave,
}));
const { story, pages } = useStory(({ state }) => ({
story: state.story,
pages: state.pages,
}));
const isUploading = useIsUploadingToStory();

// Cache it to make it stable in terms of the below timeout
Expand All @@ -46,7 +43,7 @@ function AutoSaveHandler() {
}, [autoSave]);

useEffect(() => {
if (!hasNewChanges || !autoSaveInterval || isUploading) {
if (!hasNewChanges || !autoSaveInterval || isUploading || isSaving) {
return undefined;
}
// This is only a timeout (and not an interval), as `hasNewChanges` will come
Expand All @@ -58,7 +55,7 @@ function AutoSaveHandler() {
);

return () => clearTimeout(timeout);
}, [autoSaveInterval, hasNewChanges, isUploading, story, pages]);
}, [autoSaveInterval, hasNewChanges, isUploading, isSaving]);

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function setup({
const storyContextValue = {
state: {
story: { status },
meta: { isSaving: false },
},
actions: { autoSave },
};
Expand Down