Hey!
I was playing around with dynamic slugs and noticed that when altering different routes, the website does not crash, even though it should no? For example even if I remove the "routes" key, website still working no issue, so whats the purpose of having this when creating client? Having trouble to understand.
I also was testing on this repo which was provided from Prismic (Next.js and Prismic - Documentation - Prismic) called crash-course-next repository and I tried to do same thing and website crashes.
Having trouble to understand that is it intended that if you provide wrong type etc. into "routes", the website will crash or not and also on this example repo, we are creating client twice so is this the common way to do when using Prismic with GraphQL?
Alright so been past this week trying to figure this problem and here is the solution for this (so anyone who is using GraphQL with their Prismic, this might help you with similar problem):
Decided to transfer from getServerSideProps into getStaticProps. I think this way we can make sure when building the project all the paths (landing page) exists during build time:
Now when I add new page (landing_page) into Prismic, we will handle that via revalidation.
And in order we can use the revalidation on demand, we need to use webhook and took me lot of time testing (first time playing around with them!). The most important thing we are interested regarding payload data is the documents key as it returns array of strings:
Then we can use that value and do the graphql query and give the value for id_in argument as it accepts array!
This makes this validation 200% easier for me as we don't care if user wants to add only (1) page or multiple pages as in the end it will fetch all the necessary data based on id's values and then we will revalidate the paths on each part.
Also keep in mind that we need to also give context and fetch with latest masterRef value, which we also get from the payload itself. Otherwise if this is missing, then the query will return null as it can't find the new id value from "old" data.
But now the problem is that how I can handle that when I delete one of the landing pages it will return the "404 error" page, but then how I can actually delete the page itself from cache? As my understanding only way me to delete outdated/old pages is to rebuild the project and redeploy.
I mean its not really big a problem for me, as I am doing small project for my portfolio, but then in the future I might cross into project where there might be thousands of pages (ecommerce for example).