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

! THIS IS NOT YOUR COMPONENT ! #1311

Closed
theKashey opened this issue Jul 27, 2019 · 5 comments
Closed

! THIS IS NOT YOUR COMPONENT ! #1311

theKashey opened this issue Jul 27, 2019 · 5 comments

Comments

@theKashey
Copy link
Collaborator

theKashey commented Jul 27, 2019

        ! THIS IS NOT YOUR COMPONENT !
        !  THIS IS REACT-HOT-LOADER  !

        And you are probably looking for a function component of yours
        It's hidden, but there is a way to fix this - just reconfigure your application a bit

You might see this in your code, especially if you clicked "Show Component Source" in the React Dev Tools.

You were looking for some component, and got ProxyFacade - that's how React-Hot-Loader works - it's wrapping everything with Proxies.

And you can fix it!

To fix this problem you need "react-🔥-patch", and there are tree ways how to apply it:

Webpack loader

Use a webpack-plugin to land a patch. That's the safest way.

// would only land a "hot-patch" to react-dom
{
    test: /\.js$/,
    include: /node_modules\/react-dom/,
    use: ['react-hot-loader/webpack']
},

hot-loader/react-dom alias

Use a hot-loader/react-dom with prelanded patch. See hot-loader repo for the instalation details.

// webpack.conf
...
resolve: {
    alias: {
      'react-dom': '@hot-loader/react-dom'
    }
}
...

hot-loader/react-dom yarn override

Just yarn add react-dom@npm:@hot-loader/react-dom, but only for yarn package manager.

@ivancarvalhofilho
Copy link

ivancarvalhofilho commented Jan 5, 2022

None of the mentioned fixes worked for me, what worked was changing the default react-hot-reload lib to another one such as webpack-hot-reload lib.
Ex:

// webpack.conf
module.exports = {
  ...
  entry: [
    "webpack/hot/dev-server.js", // <-- change to this
    ...
  ],
  output:{
    publicPath: '/' // <-- Webpack hot reload require this param to work properly 
  },
  devServer: {
    hot: true,
  },
 ...
}

(I was using React v17 and Router v6)

@r-vigneshwaran
Copy link

I am facing this issue and it is not working for me

@inspiraller
Copy link

inspiraller commented Apr 22, 2022

Tried all of the above methods and still have same problem
See boilerplate repo I created.

None of the above solutions work for this repo:
https://github.com/inspiraller/webpack5_hotload

index.tsx

import React, { ComponentType } from "react";
import ReactDOM from "react-dom";
import { AppContainer } from "react-hot-loader";

import App, { Props as AppProps } from "src/App";

import './index.scss'
export interface RenderProps {
  App: ComponentType<AppProps>;
}

export type TRender = (props: RenderProps) => void;
export const render: TRender = ({  App }) => {
  ReactDOM.render(
    <AppContainer>
      <App />
    </AppContainer>,
    document.getElementById("root") || document.createElement("div")
  );
};
interface HotProps extends RenderProps {
  render: TRender;
}

type THot = (props: HotProps) => void;
const handleHotReload: THot = ({ render, App }) => {
  if (module && module.hot) {
    module.hot.accept("src/App", () => {
      return render({ App });
    });
  }
};

render({ App });
handleHotReload({ render, App });

export default {};

App.tsx

import React, { FC, useEffect } from "react";
import {
  Routes,
  Route,
  BrowserRouter as Router
} from "react-router-dom";


import { Home } from "./Pages";
import { Example } from "./Pages/Example";
import { TElement } from "./types";

export interface ConfigRoutes {
  [key: string]: {
    title: string,
    path: string,
    component: TElement
  }
}
export const configRoutes: ConfigRoutes = {
  home: {
    title: "Home",
    path: `/`,
    component: <Home />,
  },
  Example: {
    title: "Example",
    path: `/Example`,
    component: <Example />,
  },

};

export interface Props {

}
const App:FC<Props> = () => {
  const routes = configRoutes
  // const location = useLocation()
  const location = document.location;
  const { pathname } = location;
  useEffect(() => {
    if (pathname) {
      const keyRoute = Object.keys(routes).find(
        (item) => routes[item].path === pathname
      );
      if (keyRoute) {
        const title = routes[keyRoute].title;
        window.document.title = title;
      }
    }
  }, [pathname]);

  console.log('Router', {routes})
  return (
    <Router>
      <Routes>
        {Object.keys(routes).map((key) => (
          <Route
            path={routes[key].path}
            element={routes[key].component}
            key={`route-${key}`}
          />
        ))}
      </Routes>
    </Router>
  );
};
export default App

@inspiraller
Copy link

inspiraller commented Apr 22, 2022

Ok I've bit the bullet and changed the npm package to - react-refresh - as advised from this README
https://www.npmjs.com/package/react-hot-loader

My updated repo:
https://github.com/inspiraller/webpack5_hotload/tree/feature/react-refresh

@minhnh87
Copy link

It works for me (the first way). Thank you so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants