Register

Implementing server-side rendering on this site with Nuxt 3

kyle

Nuxt is pretty nice to use in most ways, and the migration was largely straightforward. Its convention-heavy approach is nice and fairly intuitive, and it makes data-fetching a breeze with useFetch. It does have some drawbacks, as well, namely:

  • The unit tests for forms aren't as comprehensive anymore, because setErrors doesn't work properly in the Nuxt tests like it did with vanilla Vue. This isn't horrible, because I do have e2e coverage over these features, but having faster, cheaper unit tests would be nice when I'm working on the components, because I would get feedback in a fraction of the time.

  • The e2e tests now need a delay. This breaks my heart to have to do, because it means we are often not running the tests as quickly as we can (the slowdown is currently only a few seconds off from where it was before, but will increase as we have more tests), but it's necessary for now because on page load Nuxt swaps out the server-rendered DOM nodes with new ones on the client. This breaks Playwright's auto-waiting for inputs, because what tends to happen is:

    1. The test at some point navigates to a page and tries to type into an input field.
    2. Playwright waits until it can interact with the input, then types into it.
    3. Nuxt replaces the input with a different one, losing the value.
    4. The test fails because the input is empty.

    There may be some way to detect once this swap has happened, and it happens too fast to bother a real, human user, but so far I've decided to just settle with the easy way out.

  • I no longer have OpenTelemtry traces working in the frontend. The old instrumentation code doesn't work anymore, and I couldn't figure out how to get it working after an hour or two of trying. I found an open PR about adding support, but it seems like a neglected issue. It looks like others may have gotten it working, so there is some hope, but I'll return to it later.

I wish Nuxt weren't so all-or-nothing--it's a heavy framework and can be kind of a black box at times--but overall I think it's useful. Until Vue's from-scratch SSR support gets smoother (which I don't believe is a priority for them, because things like Nuxt exist), I think I will probably start new Vue projects using Nuxt.

  • programming
First posted 8/31/2024, 4:14:19 PM
Updated 8/31/2024, 4:16:05 PM