Gatsby Styles Breaking -- Netlify Deployment - reactjs

This is my first post here, so forgive me if I am not upfront with anything.
I have a Gatsby site that is being deployed via netlify.
Been running into a very random bug that I have searched the dark reaches of the internet but cannot find the fix for.
Intermediately, the site styles on my website break completely. Upon inspecting, I see my global.css file isn’t being applied. Upon a refresh, this issue goes away.
Site is accessible by this link: https://ellicottrealty.netlify.app/ 2
Upon looking online, I see that I should define the css export in my Gatsby-browser.js file.
I have done so explicitly by writing the following:
const React = require(“react”)
// gatsby-browser.js
import “./src/global.css”
However this is still happening in my app.
Screenshot attached for reference. Any help would be very helpful!
Thanks Guys!
Example of Broken Styles
Loom video for better visual context: https://www.loom.com/share/05e9234636304eeea44d2ae8337c542c

I think you're looking at a symptom and not the cause. I see that your site is loading infinitely on the /properties route. It's very hard to debug the problem without the total context, but I believe the infinite loop is in this code.
React.useEffect(() => {
console.log("ran");
if (searchOptions) {
console.log(searchOptions);
if (searchOptions.label) {
console.log(searchOptions.label);
Cookies.set("locationLabel", JSON.stringify(searchOptions.label));
}
console.log("ran");
services.repliers.getListings({ ...searchOptions, page }).then(setListings);
}
}, [searchOptions, page]);
Like I said before, it's hard to figure out what your exact problem is without enough context. Maybe you should add listings to the dependency array as well?

Related

Trouble With GitHub Pages

I've seen a few of these posts on StackOverflow already, though I really can't seem to get mine working no matter what I try.
I am trying to host a webpage, though when deploying I am left with a blank screen, and the following error in the console:
Uncaught SyntaxError: Unexpected token '<' in main.e7fa3b75.js:1
I've seen posts which suggest it is a problem with the pathing to my static files, though I cant seem to sort it out.
This post suggests I should remove an extension from my package.json, though I don't use that extension.
This post says I should remove the repository name from the homepage field in the package.json, though that also wouldn't work for me.
I'm out of ideas, here is the repo, if someone doesn't mind taking a look?
I have got it to render the website for a few moments, only to disappear to the same white screen moments later. There are no problems if I run the page on local host.
UPDATE
I have since got the application to host, but only if I explicitly visit the URL of the landing page.
https://jcdw99.github.io/
From the landing page there is a /papers route which can be reached from the navbar. If you press on the button, the page renders. Though, if you try to explicitly view the page, by manually visiting
https://jcdw99.github.io/papers it returns a 404.
Any help?
Try <HashRouter> instead of <BrowserRouter> since Github pages don't support HTML5 history API (see notes on client side routing) but React BrowserRouter uses it. See this question with similar problem.
One observation is if you navigate directly using # in the url, like https://jcdw99.github.io/#/papers it works!

Issue rendering ReactJS production build

I have created a three page react application using react-router-dom that also uses a proxy to make calls to the node API on my web server. When running the application in development everything runs as expected. My issues are after building it no longer renders anything on the screen. The weird thing is that I'm not receiving any errors in the console but through debugging I've noticed it does load the page until I call my API and then it goes blank. Does anyone know why this may be affecting the production build but not the development build? I've added:
"homepage": "."
to my package.json as it worked for someone else who asked the same question but it has made no difference for me. I've linked the code if anyone wants to take a look. Any insight would be greatly appreciated.   Link to code
For anyone else who may stumble across this. It was due to issues with the proxy in the package.json. After removing the proxy and calling the API manually, there were no longer any issues.

Deploy React app with JSON-server as backend

I made a simple CRUD application that is supposed to be an appointment manager based on Traversy's Task Manager (found here: https://www.youtube.com/watch?v=w7ejDZ8SWv8), and now I'm trying to publish it.
I have found a number of guides but none have helped me. I'll list them below:
https://dev.to/nikita_guliaev/deploying-create-react-app-with-json-server-as-backend-to-github-3pp9
https://github.com/YoussefZidan/fake-server
https://www.youtube.com/watch?v=5cbFLDe4OAA
The one that I believe came the closest to help me do what I want is the first one listed. If I follow it to the letter, all I get is the background but nothing else. I experimented trying to run it on my pc, changing the fetch requests from localhost to https://my-json-server.typicode.com/jmiguelcastellanosj/ap-m/appointments but it didn't work. I removed the homepage property from the package.json file and it worked on my computer (changes didn't persist, but from my understanding that's expected from the service provided by typicode), tried deploying it but it didn't even load the background.
I could describe my other attempts with the other two guides, but other than finding out that heroku exists, I don't think I got much useful learning from them.
Ideally, I would like the changes to persist after reloading the application, but right now that seems like a pipedream considering it doesn't even work once deployed.
I have a feeling that the reason for this app not working is related to the fetch requests (found in Dashboard.js, AddAppointmentForm.js, EditAppointment.js, Appointment.js), but I really don't know.
This is my first time trying to deploy anything, so I have no idea what it is that I'm missing or doing wrong, and having spent days trying and failing at this, I'm at a complete loss on what to do. Help would be greatly appreciated. Thank you.
My repo can be found here: https://github.com/jmiguelcastellanosj/ap-m
Right now it should be able to work locally with json-server as backend.
Before building set your "homepage" in package.json to "https://jmiguelcastellanosj.github.io/ap-m", this will let github pages load your files properly.
Also if your routing doesn't work properly, in each of your routes add "/ap-m" in front of your path (So path='/' becomes path="/ap-m")

Is there a way to handle URIError in React?

Some days ago I was working on an issue for my job where a page on React couldn't "catch" an error when someone tried to navigate using a bad URL that had the percentage sign (%) that can't be decoded.
The React project uses react-router-dom to handle navigation by showing different views when accessing different URL's (it even has a 404 route when it has no matching routes), and the struture looks very similar to React Router's 404 example, here's the link where you can try for yourself adding /% to the URL from the sandbox's browser and understand in a better way the problem.
In my local-development scenario the page only shows the stack trace in the following image (also check the console output).
I understand that it if someone provides a bad URL that can't be decoded this error will throw and therefore the page will not run. I've been looking for a while and haven't found nothing related to how to catch it on React (I'm not sure if that's really possible).
Any suggestions are welcome!

I deleted a React component that was never used, but now the page won't render... huh?

I had a component in a ReactJS app I am working on that I sweeeearrr is not used anywhere. It even gave me the warning that "footer is defined but not used'. It isn't render anywhere and it never did anything, modify state... yet I'm getting an error message that says that the page cannot be rendered because the file is missing after I deleted it.
Is this simply a matter that I must be missing a connection somewhere?
A few troubleshooting tips. It's helpful if you include these details in your question so we know what you've already tried. Try one at a time and see if the error resolves:
Restart your server (webpack-dev?).
Clear browser cache or open an incognito window and load the page again.
String-search your project for the file name.
yet I'm getting an error message that says that the page cannot be rendered because the file is missing after I deleted it.
An unused import / require statement is left in there.
Solution
Search for filename in the entire code base and remove usage.
More
Something like TypeScript would have caught this at compile time.
A bit late but I faced this exact same problem. Here is what I did:
In VSCode, I opened command pallete and reloaded typescript
I restarted react server
And it worked for me.

Resources