Sfoglia il codice sorgente

fix pagePath mutation on init

Yuki Takei 3 anni fa
parent
commit
d1bcf9fb59

+ 1 - 1
packages/app/src/components/PageEditor/CodeMirrorEditor.jsx

@@ -101,7 +101,7 @@ class CodeMirrorEditor extends AbstractEditor {
     this.state = {
       isGfmMode: this.props.isGfmMode,
       isLoadingKeymap: false,
-      isSimpleCheatsheetShown: this.props.isGfmMode && this.props.value.length === 0,
+      isSimpleCheatsheetShown: this.props.isGfmMode && this.props.value?.length === 0,
       isCheatsheetModalShown: false,
       additionalClassSet: new Set(),
       isEmojiPickerShown: false,

+ 5 - 4
packages/app/src/pages/[[...path]].page.tsx

@@ -238,14 +238,15 @@ const GrowiPage: NextPage<Props> = (props: Props) => {
   }
 
   const pageId = pageWithMeta?.data._id;
+  const pagePath = pageWithMeta?.data.path ?? props.currentPathname;
 
   useCurrentPageId(pageId);
   useSWRxCurrentPage(undefined, pageWithMeta?.data); // store initial data
   useSWRxPageInfo(pageId, undefined, pageWithMeta?.meta); // store initial data
-  useIsTrashPage(_isTrashPage(pageWithMeta?.data.path ?? ''));
-  useIsUserPage(isUserPage(pageWithMeta?.data.path ?? ''));
-  useIsNotCreatable(props.isForbidden || !isCreatablePage(pageWithMeta?.data.path ?? '')); // TODO: need to include props.isIdentical
-  useCurrentPagePath(pageWithMeta?.data.path);
+  useIsTrashPage(_isTrashPage(pagePath));
+  useIsUserPage(isUserPage(pagePath));
+  useIsNotCreatable(props.isForbidden || !isCreatablePage(pagePath)); // TODO: need to include props.isIdentical
+  useCurrentPagePath(pagePath);
   useCurrentPathname(props.currentPathname);
   useEditingMarkdown(pageWithMeta?.data.revision?.body);
   const { data: grantData } = useSWRxIsGrantNormalized(pageId);