Next.js - using cached files on a live server breaks the app - reactjs

I am just starting with Next.js and have this weird issue and not sure what is the root cause.
I am building a package that has this var
const bar = typeof window !== "undefined" ? "foo" : undefined;
I also have a next.js app that uses that package as a dependency. The app is hosted on a github page (github.io).
When loading the app without cache (mark "Disable cache" on chrome Network tab) the app renders as expected, i.e bar is foo. (It also works when doing hard refresh - cmd+shift+R)
But when loading the app using the cached files, bar is undefined.

Related

react-scrollspy-nav causes error after deploying react app

I want to active menu on scroll in my react app. I have used a react-scrollspy-nav for this functionality. It works fine when i run it on local server but when i deploy so it shows a blank screen
i have used a react-scrollspy-nav in my app, which is working perfectly on local server on my laptop but after deploying on netlify, it shows blank screen with an error on console that says
Uncaught TypeError: Super expression must either be null or a function
at ScrollspyNav.js:423:1
Link of my react app
If i remove this module react-scrollspy-nav and deploy it, my app does not show blank screen and works well but without the functionality of scrollspy which i want in my app

Cannot refresh browser for new version of react app

I try to refresh react app on browser side for new version with this line of javascript :
window.location.reload(true);
It doesn't work on desktop and android Chrome, which seems to keep displaying the cached version it has.

Nextjs 404 error on reload/ refresh action

I'm using Nextjs for a front-end application and dotnet core 3.1 for the Web API. There are some pages that are static and other that are dynamic I followed the official documentation to achieve this. On development mode (local machine) everything works fine. Both static and dynamic routes are working properly and fetching data from the dontnet core Web API.
However, when publishing the Nextjs app following this steps:
yarn build
yarn export
An out folder is generated at the root of the project
The content of that folder is uploaded to the server
After, the deployed files are uploaded and when loging to the app, it redirects to the main page (until here is working OK), but as soon as I click on the reload page botton (Chrome) I am gettint the 404 error.
Looking at the console in the developer tools I got this:
I found this Stackoverflow link with same issue but there the answer is to use Express for server routing. In my case I am using dotnet core Web API for server requests. So, not sure how to do that.
Is there a way to fix this from the client side? Might be a configuration is missing?
The only thing I noticed while doing the export was a message saying: No "exportPathMap" found. Not sure if that would the the reason.
I had got similar issue in react when all of my pages after building and exporting had ".html" extensions. I solved it by the following code in next.config.js file.
next.config.js
module.exports = {
exportTrailingSlash: true,
}
Note: Do not work with the above code while in development. Use it just before building the project.
You can find the documentation link here: https://nextjs.org/docs/api-reference/next.config.js/exportPathMap#adding-a-trailing-slash.
UPDATE
The above code was for next.js v9.3.4 which I was using at that time. For newer versions below code should be used according to docs.
next.config.js
module.exports = {
trailingSlash: true,
}
it has been fixed update your nextjs package
npm install next#latest
based on the current version of Next js you have, visit here to see if there's any breaking change before updating what you have
I had a similar issue where after deploying the out folder created by next export all URL's would redirect me to the homepage. Everything was working fine during development and all URL's were accessible with next/link but in order to access pages with a URL I had to add a .html extension at the end of the URL.
Because I needed a quick workaround I added a useEffect block in the _app.tsx file for rerouting so that upon landing on the homepage it would act as if a Link component was clicked redirecting to the entered URL.
useEffect(()=>{
router.push(window.location.href)
},[])

Cannot hide the URL bar in a TWA gatsby react app on Android

I have my app pushed out currently to google play. However when I download and install, the url bar still shows on the app.
Steps I've taken to solve this with no changes:
I realized I was using the upload certificate in my assetlinks.json, so I copied and pasted the app signing certificate from my google play console in it instead.
In my manifest.webmanifest file, I was using display: 'minimal-ui' in my gatsby-config.js file, so I changed it to display: 'standalone' and rebuilt the project, allowing the change to carry over to the manifest.webmanifest file.
Still no change. When I run the app in Lighthouse audit, the simulator doesn't show a URL bar, but it does on my phone when I install it. Anything else to try?

"The webpage at chrome-extension://myextensionid/ might be temporarily down or it may have moved permanently to a new web address. ERR_UNEXPECTED"

I am developing a react chrome extension.
I have a footer bar to navigate across my pages(components).
I am using react-router-dom to switch/route between pages.
My extension works perfectly when debugging but, after I build it (npm run build) and Load Unpacked at my extensions, the first page renders good but when I click my footer navigation buttons, my extension shows this message:
The webpage at chrome-extension://myextensionid/ might be temporarily down or it may have moved permanently to a new web
address. ERR_UNEXPECTED
Is it because I did not publish it yet, routing only works after I publish my extension?
Any ideas what can be wrong, can you please help me with this issue?

Resources