Stepping on a Bug š
Published: 5/12/2022
The Issue
My Lent website is supposed to show you the reflection from the current day of Lent, if we are in Lent. Otherwise, it should show you the reflection from the first day of Lent. Instead, the site is stuck on day 41 for some reason š¤
Going in, I know that the site is querying the date of Easter from Google Calendar API, and then subtracting days to calculate the start of Lent. Then it should calculate the number of days between today and the start of Lent. If today is a day within lent, it should display that page, otherwise, display day 1. Letās take a lookā¦
Oh good, itās only happening in production
Firing up my development environment locally, I see that the problem is only happening in production. Awesome! Iām fairly sure Iāve had this problem before, and Iād be willing to bet that thereās an issue with connection to the Google Calendar API.
However, another thing occurs to meā¦Perhaps the issue is that the site was built on day 40 of lent, and is not regenerating every time I hit the page. Iām going to test this theory by going to cloudflare and redeploying the build to see if the site is built on the correct day.
I rebuilt the page, and now at least the correct day is highlighted in the sidebar. However the content is still wrong and Iām wondering if it was cached.
How does this site even work š²
So, in a perfect world the layout file for the index page hits the dates.json, gets the current day of Lent, if weāre in lent, and otherwise passes day of zero to the index page, which in turn fetches the relevant markdown file to serve the visitor.
The problem is that since weāre out of Lent, I canāt debug the issue, since zero is being passed, post-rebuild and Cloudflare-cache-purge. Hmm.
I added a ācurrent-dateā to the info returned by dates.json, which I am having the _layout file pass to the Footer. Now I can at least see the date the page was built. I can check back in soon and see if thereās a caching/build issue.
Resolution
Oh bother. Looks like I set prerender=true in svelte.config at some point. Cloudflare was displaying the site as a static rather than dynamic site. Thatāll probably do it š¤¦
Going forward
I think this might be a good test case for the testing library that is now shipping with Svelte. It would be cool to learn how to stub out the Google Calendar API.
Follow up
I checked on this the following day. The date in the footer was current for all pages, which means that I was not correctly understanding how prerendering works. I expected the time in the footer of the index page to be current when I hit the index page, but to the build time for the static pages that were not the index page. Perhaps the client-side router is keeping everything but the text section intact when it navigates between pages. Iām going to dig in further.