Lessons Learned
» 2026-01-31, 20:24
Today I randomly clicked on one of my devlogs after discovering it on a search engine, only to find… an error? The website showed 500 (internal error), the console showed 404 (page not found). This was very strange considering the page opened no problemo on my dev server (using npm run dev). Even stranger: navigating to the page manually was no problem, but refreshing the page or hotlinking triggered the error. It didn’t make any sense to me, as this didn’t affect all pages.
I tested and tested and then noticed – hold on, the first three devlogs work but all older ones error out. This was interesting, as I recently changed the devlog overview page so that it would only show the first three entries and presented a button to view all the others as well – hidden by default. Once I removed the button and showed all entries by default, it worked. Phew.
I suspect SvelteKit has issues rendering pages that aren’t directly linked anywhere – though how plausible that is, I’m not sure, as I was able to open a page that I know for sure isn’t linked anywhere just by typing in its direct link…
I had this fixed just before realising that the devlog overview page itself errors out on refresh as well! Even more strangely: the blog overview page was also affected. I suspected there was some common cause, and indeed, journalctl revealed it: a function I called to map a Map to an Array failed because the Map didn’t exist. I used these Map objects to store data about individual posts, so their functionality was partially shared between the devlog and the blog.
To be honest, this error still doesn’t make any sense to me, but I was able to fix it by creating a custom data type that mimicked a key-value structure. Something about the Map structure caused issues as it cleared its values on refresh or something. This also made remapping a lot simpler as the data was then already in Array format.
Lesson learned: if you ever work on something that you need to transfer over from a work-in-progress version to a finished version, make sure that the finished version works as you intend it to! Do not assume that everything will work fine.