#404 error for dynamic route that is actually processed o_o

5 messages · Page 1 of 1 (latest)

shell flume
#

EDIT: This is due to a bug related to i18n. No need to read and try to answer.


Hi.

Today I found myself suffering from a very strange error after a big refactor.

Small disclaimer:

Even if that was a big refactor, the changes regarding how a route was configured are so subtle that it is being almost impossible for me to to pinpoint what's actually different...

So I'll limit my explanation to what I have at this time, leaving aside changes from its previous state.

So, that's what I have, an .astro template in the following local path:
src/pages/email/confirm/[validationKey].astro

Inside that file, I set export const prerender = false to ensure that it's a dynamic route (astro's output is configured as hybrid).

Now, in the "preface" (before the ---), I perform some actions, and they actually work fine, I can see them logged on the console every time I visit a page (you can see it on the attached screenshot, printing 'J' is the last step of the "preface", so there is no error prior to that).

Also, on the "rendering" part, I commented out everything and just added static content, a Hello World to discard any problem related with the components...

but, as you can see... it's returning 404 (without content, not even the Hello World, to make it worse).

Any idea of what I might be doing wrong?

#

For context, the code of [validationKey].astro (of course now it's uglier than indented, because it's full of commented-out code and console.log calls):

---
import { z } from 'zod'

import type { Email } from '@/types/dtos.js'
import { normalizeEmail } from '@/utils/email.js'
import { getEmailData, markEmailAsValidated } from '@/utils/repositories/email'

export const prerender = false

console.log('A')

const email = Astro.url.searchParams.get('email')

console.log('B')
console.log('C')
console.log('D')

console.log('E')
const emailValidator = z.string().email()
console.log('F')

const { validationKey } = Astro.params

console.log('G')
console.log(validationKey)

let error = false
console.log('H')

const handleConfirm = async () => {
  console.log('H1')
  if (!email || !validationKey) {
    error = true
    return
  }
  // irrelevant, because it leaves the function in the previous `if`
}

console.log('I')
await handleConfirm()
console.log('J')

---

<>We never get to see this :(</>
<!-- commented out old components -->
shell flume
#

A much simplified version that still fails (returns empty response with 404 status code; but still generates the log lines with A and B, so it is clear that this code is being executed)

---

export const prerender = false

console.log('A')
const { validationKey } = Astro.params
console.log('B')

---

<div>
<p>We never get to reach this point</p>
<p>{validationKey}</p>
</div>
shell flume
#

Nope, it's actually 'always'. I actually pinned down the problem, it's because of i18n wanting to control all routes