0

Fresh install without any modification beside a console.log that is located on welcome.jsx and it is displayed twice. What can I do to fix this? This will affect all other functionalities all axios, if there will be, will be executed twice. How can I fix this? Thank you

I have tested with fresh install of laravel + inertia only and it happens too. I have instaled them on dedicated server and localhost too. I have tried laravel + breeze too same problem.

This is my package.json this is the composer.json

the console.log in the Welcome.jsx the change the console in the browser's console the double log

i run it with npm run dev and npm run build for both is the same.

dGame
  • 1
  • 1
  • How do you run your project can you post that – tp45 May 09 '23 at 07:02
  • npm run build "private": true, "scripts": { "dev": "vite", "build": "vite build && vite build --ssr" }, "devDependencies": { "@headlessui/react": "^1.4.2", "@inertiajs/react": "^1.0.0", "@tailwindcss/forms": "^0.5.3", "@vitejs/plugin-react": "^3.0.0", "autoprefixer": "^10.4.12", "axios": "^1.1.2", "laravel-vite-plugin": "^0.7.2", "postcss": "^8.4.18", "react": "^18.2.0", "react-dom": "^18.2.0", "tailwindcss": "^3.2.1", "vite": "^4.0.0" } – dGame May 09 '23 at 07:08
  • I think if you followed the starter kit correctly you should just run like ```npm run dev``` – tp45 May 09 '23 at 07:14
  • @dGame Please [edit] your question and post relevant information there, not in the comments. Thanks – brombeer May 09 '23 at 07:15
  • @tp45 same on npm run dev and for a production site you will run build not dev thank you for trying to help me – dGame May 09 '23 at 07:18
  • @brombeer i have add package.json and composer.json please let me know if you need more info I can provide anything. thank you for trying to help – dGame May 09 '23 at 07:18
  • Not sure what you mean? Does it send two identical requests and get the same result from both? Can you share an example pair of requests that are duplicated? (incl. request and response headers) – apokryfos May 09 '23 at 07:31
  • 1
    I just create a fresh install following https://laravel.com/docs/10.x/starter-kits everything is fine. Please show us what it shows when you run it locally and also show the console – tp45 May 09 '23 at 07:36
  • @apokryfos fresh install add a console.log in the return area, and after build you will see that console.log twice in the browser console. – dGame May 09 '23 at 07:36
  • @tp45 please check I have add the prints in the post. – dGame May 09 '23 at 07:41
  • I managed to reproduce the double console, I added the console and ran ```npm run build``` then php artisan serv and it console logged twice , I don't think this is a problem and it will not course problems for you try logging somewhere else and check – tp45 May 09 '23 at 08:30
  • @tp45 if you add any axios for example it will be executed twice which can cause problems... we as company are making sports betting sites and we need axios requests and its strange to be executed twice. Thank you so much for checking. – dGame May 09 '23 at 08:35

1 Answers1

0

Use useEffect to make sure nothing executes twice like below

 useEffect(() => {
        console.log(user); // this runs once
        axios
            .get('https://jsonplaceholder.typicode.com/todos/1')
            .then((res) => {
                console.log(res.data); // this runs once
            })
            .catch((err) => {
                console.log(err);
            });
    }, []);

I run php artisan serv and run npm run dev for hot reload every time I make changes enter image description here

Here is my console
enter image description here

tp45
  • 123
  • 4
  • 13
  • yes, that is correct, but still that console.log it is displayed twice and all the html that is on that return. – dGame May 09 '23 at 10:50
  • if you console log anywhere in react it will console multiple time please check this and you can go to their docs as well https://stackoverflow.com/questions/67307443/why-does-a-function-outside-useeffect-get-called-while-a-function-inside-useeffe the html part I don't understand – tp45 May 09 '23 at 11:01
  • if you have: https://imgur.com/6cUSzNF somethig like this and the useEffect is inside Announcement it will be executed twice – dGame May 09 '23 at 12:58