Przeglądaj źródła

re-impl blinking header at boot

Yuki Takei 3 lat temu
rodzic
commit
5792f38c73

+ 5 - 29
packages/app/src/components/Page.jsx

@@ -195,38 +195,14 @@ export const Page = (props) => {
 
   const pageRef = useRef(null);
 
-  // *************************** Blink header at boot ***************************
-  const blinkOnInit = useCallback(() => {
-
-    const result = blinkSectionHeaderAtBoot();
-
-    if (result != null) {
-      mutateBlinkedAtBoot(true);
-    }
-  }, [mutateBlinkedAtBoot]);
-
-  const blinkOnInitDebounced = useMemo(() => debounce(500, blinkOnInit), [blinkOnInit]);
-
-  const observerForBlinkingOnInit = useCallback((elem) => {
-    if (isBlinkedAtBoot || elem == null) {
+  useEffect(() => {
+    if (isBlinkedAtBoot) {
       return;
     }
 
-    const observerCallback = (mutationRecords) => {
-      mutationRecords.forEach(() => blinkOnInitDebounced());
-    };
-
-    const observer = new MutationObserver(observerCallback);
-    observer.observe(elem, { childList: true, subtree: true });
-
-    // first call for the situation that all rendering is complete at this point
-    blinkOnInitDebounced();
-
-    return function cleanup() {
-      observer.disconnect();
-    };
-  }, [blinkOnInitDebounced, isBlinkedAtBoot]);
-  // *******************************  end  *******************************
+    blinkSectionHeaderAtBoot();
+    mutateBlinkedAtBoot(true);
+  }, [mutateBlinkedAtBoot]);
 
   // // set handler to open DrawioModal
   // useEffect(() => {

+ 3 - 1
packages/app/src/pages/[[...path]].page.tsx

@@ -53,7 +53,8 @@ import {
   useAppTitle, useSiteUrl, useConfidential, useIsEnabledStaleNotification,
   useIsSearchServiceConfigured, useIsSearchServiceReachable, useIsMailerSetup,
   useAclEnabled, useIsAclEnabled, useHasSlackConfig, useDrawioUri, useHackmdUri,
-  useNoCdn, useEditorConfig, useCsrfToken, useIsSearchScopeChildrenAsDefault, useCurrentPageId, useCurrentPathname, useIsSlackConfigured, useGrowiRendererConfig,
+  useNoCdn, useEditorConfig, useCsrfToken, useIsSearchScopeChildrenAsDefault, useCurrentPageId, useCurrentPathname,
+  useIsSlackConfigured, useGrowiRendererConfig, useIsBlinkedHeaderAtBoot,
 } from '../stores/context';
 import { useXss } from '../stores/xss';
 
@@ -160,6 +161,7 @@ const GrowiPage: NextPage<Props> = (props: Props) => {
   // useIsAbleToDeleteCompletely(props.isAbleToDeleteCompletely);
   useIsSharedUser(false); // this page cann't be routed for '/share'
   useIsEnabledStaleNotification(props.isEnabledStaleNotification);
+  useIsBlinkedHeaderAtBoot(false);
 
   useIsSearchServiceConfigured(props.isSearchServiceConfigured);
   useIsSearchServiceReachable(props.isSearchServiceReachable);

+ 2 - 2
packages/app/src/stores/context.tsx

@@ -214,8 +214,8 @@ export const useGrowiRendererConfig = (initialData?: GrowiRendererConfig): SWRRe
   return useStaticSWR('growiRendererConfig', initialData);
 };
 
-export const useIsBlinkedHeaderAtBoot = (): SWRResponse<boolean, Error> => {
-  return useStaticSWR('isBlinkedAtBoot', undefined, { fallbackData: false });
+export const useIsBlinkedHeaderAtBoot = (initialData?: boolean): SWRResponse<boolean, Error> => {
+  return useStaticSWR('isBlinkedAtBoot', initialData);
 };