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

fix: Initialize grant correctly after when page transition #8633

Merged
merged 5 commits into from
Apr 15, 2024
Merged
Changes from 2 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: 8 additions & 3 deletions apps/app/src/client/services/page-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { SubscriptionStatusType } from '@growi/core';
import urljoin from 'url-join';

import type {
IApiv3PageCreateParams, IApiv3PageCreateResponse, IApiv3PageUpdateParams, IApiv3PageUpdateResponse,
yuki-takei marked this conversation as resolved.
Show resolved Hide resolved
IApiv3PageCreateParams, IApiv3PageCreateResponse,
} from '~/interfaces/apiv3';
import { useEditingMarkdown, usePageTagsForEditors } from '~/stores/editor';
import { useCurrentPageId, useSWRMUTxCurrentPage, useSWRxTagsInfo } from '~/stores/page';
import {
useCurrentPageId, useSWRMUTxCurrentPage, useSWRxIsGrantNormalized, useSWRxTagsInfo,
} from '~/stores/page';
import { useSetRemoteLatestPageData } from '~/stores/remote-latest-page';
import loggerFactory from '~/utils/logger';

Expand Down Expand Up @@ -107,6 +109,7 @@ export const useUpdateStateAfterSave = (pageId: string|undefined|null, opts?: Up
const { mutate: mutateTagsInfo } = useSWRxTagsInfo(pageId);
const { sync: syncTagsInfoForEditor } = usePageTagsForEditors(pageId);
const { mutate: mutateEditingMarkdown } = useEditingMarkdown();
const { mutate: mutateGrant } = useSWRxIsGrantNormalized(pageId);

// update swr 'currentPageId', 'currentPage', remote states
return useCallback(async() => {
Expand All @@ -129,6 +132,8 @@ export const useUpdateStateAfterSave = (pageId: string|undefined|null, opts?: Up
mutateEditingMarkdown(updatedPage.revision.body);
}

await mutateGrant();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ページ保存時にgrantデータがmutateされておらず、ページ移動しても初期化時に入れたgrantデータが保持されたままだったことが不具合の原因だったので、ページ保存時にgrantデータをmutateするようにしました

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useSWRxApplicableGrant も同様の理屈で mutate する必要があるんじゃないかな

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

その必要がありそうだったので追加しました。


const remoterevisionData = {
remoteRevisionId: updatedPage.revision._id,
remoteRevisionBody: updatedPage.revision.body,
Expand All @@ -139,7 +144,7 @@ export const useUpdateStateAfterSave = (pageId: string|undefined|null, opts?: Up
setRemoteLatestPageData(remoterevisionData);
},
// eslint-disable-next-line max-len
[pageId, mutateTagsInfo, syncTagsInfoForEditor, mutateCurrentPageId, mutateCurrentPage, opts?.supressEditingMarkdownMutation, setRemoteLatestPageData, mutateEditingMarkdown]);
[pageId, mutateTagsInfo, syncTagsInfoForEditor, mutateCurrentPageId, mutateCurrentPage, opts?.supressEditingMarkdownMutation, mutateGrant, setRemoteLatestPageData, mutateEditingMarkdown]);
};

export const unlink = async(path: string): Promise<void> => {
Expand Down