Ver Fonte

add rendererErrorMessage

Naoki427 há 9 meses atrás
pai
commit
70bd44ba8f

+ 18 - 0
apps/app/src/client/components/Common/RendererErrorMessage.tsx

@@ -0,0 +1,18 @@
+import React from 'react';
+
+export const RendererErrorMessage: React.FC = () => {
+  return (
+    <p
+      style={{
+        color: 'red',
+        backgroundColor: 'white',
+        padding: '0.75rem',
+        borderRadius: '4px',
+      }}
+    >
+      ⚠️ <strong>Developer Warning:</strong>{' '}
+      <code>rendererOptions</code> is <code>null</code>
+      . Make sure to call <code>useRendererConfig()</code> in your page component to initialize it properly.
+    </p>
+  );
+};

+ 2 - 0
apps/app/src/client/components/PagePresentationModal.tsx

@@ -16,6 +16,7 @@ import { usePagePresentationModal } from '~/stores/modal';
 import { useSWRxCurrentPage } from '~/stores/page';
 import { usePresentationViewOptions } from '~/stores/renderer';
 
+import { RendererErrorMessage } from './Common/RendererErrorMessage';
 
 import styles from './PagePresentationModal.module.scss';
 
@@ -87,6 +88,7 @@ const PagePresentationModal = (): JSX.Element => {
         <button className="btn-close" type="button" aria-label="Close" onClick={closeHandler}></button>
       </div>
       <ModalBody className="modal-body d-flex justify-content-center align-items-center">
+        {rendererOptions == null && <RendererErrorMessage />}
         { rendererOptions != null && isEnabledMarp != null && (
           <Presentation
             options={{

+ 5 - 8
apps/app/src/stores/renderer.tsx

@@ -6,7 +6,6 @@ import useSWR, { type SWRConfiguration, type SWRResponse } from 'swr';
 import { getGrowiFacade } from '~/features/growi-plugin/client/utils/growi-facade-utils';
 import type { RendererOptions } from '~/interfaces/renderer-options';
 import type { RendererConfigExt } from '~/interfaces/services/renderer';
-import { DEFAULT_RENDERER_CONFIG } from '~/services/renderer/default-renderer-config';
 import { useRendererConfig } from '~/stores-universal/context';
 import { useNextThemes } from '~/stores-universal/use-next-themes';
 import loggerFactory from '~/utils/logger';
@@ -185,17 +184,15 @@ export const useCustomSidebarOptions = (config?: SWRConfiguration): SWRResponse<
 
 export const usePresentationViewOptions = (): SWRResponse<RendererOptions, Error> => {
   const { data: currentPagePath } = useCurrentPagePath();
-  const rendererConfigRaw = useRendererConfigExt();
+  const rendererConfig = useRendererConfigExt();
 
-  const rendererConfig = rendererConfigRaw ?? DEFAULT_RENDERER_CONFIG;
+  const isAllDataValid = currentPagePath != null && rendererConfig != null;
 
   useEffect(() => {
-    if (rendererConfigRaw == null) {
-      logger.warn('RendererConfig is undefined or missing. Using DEFAULT_RENDERER_CONFIG.');
+    if (rendererConfig == null) {
+      logger.warn('RendererConfig is undefined or missing.');
     }
-  }, [rendererConfigRaw]);
-
-  const isAllDataValid = currentPagePath != null;
+  }, [rendererConfig]);
 
   return useSWR(
     isAllDataValid