Skip to content

Commit

Permalink
Fix react fast refresh issue in router
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithmohan committed Nov 3, 2024
1 parent 54a3701 commit 7d7f08b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useContext, useEffect, useMemo } from 'react';
import React, { useEffect, useMemo } from 'react';
import type { PlacesType } from 'react-tooltip';
import { Icon } from '@mdi/react';
import cx from 'classnames';

import { BodyVisibleContext } from '@/core/router';
import useAutoFocusRef from '@/hooks/useAutoFocusRef';
import useBodyVisibleContext from '@/hooks/useBodyVisibleContext';

type EndIcon = {
icon: string;
Expand Down Expand Up @@ -64,7 +64,7 @@ const Input = React.memo((props: Props) => {
value,
} = props;

const bodyVisible = useContext(BodyVisibleContext);
const bodyVisible = useBodyVisibleContext();
const inputRef = useAutoFocusRef(autoFocus, bodyVisible);
const [isShow, setIsShow] = React.useState(false);

Expand Down
5 changes: 2 additions & 3 deletions src/core/router/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* global globalThis */
import React, { createContext, useEffect, useRef, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { useSelector } from 'react-redux';
import { Navigate, Route } from 'react-router';
import { RouterProvider, createBrowserRouter, createRoutesFromElements } from 'react-router-dom';
import * as Sentry from '@sentry/react';

import ErrorBoundary from '@/components/ErrorBoundary';
import { useSettingsQuery } from '@/core/react-query/settings/queries';
import { BodyVisibleContext } from '@/hooks/useBodyVisibleContext';
import SentryErrorBoundaryWrapper from '@/pages/SentryErrorBoundaryWrapper';
import Collection from '@/pages/collection/Collection';
import Series from '@/pages/collection/Series';
Expand Down Expand Up @@ -130,8 +131,6 @@ const router = sentryCreateBrowserRouter(
),
);

export const BodyVisibleContext = createContext(false);

const Router = () => {
const apikey = useSelector((state: RootState) => state.apiSession.apikey);
const webuiPreviewTheme = useSelector((state: RootState) => state.misc.webuiPreviewTheme);
Expand Down
7 changes: 7 additions & 0 deletions src/hooks/useBodyVisibleContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createContext, useContext } from 'react';

export const BodyVisibleContext = createContext(false);

const useBodyVisibleContext = () => useContext(BodyVisibleContext);

export default useBodyVisibleContext;

0 comments on commit 7d7f08b

Please sign in to comment.