Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calling useVingKind().all() when doing an SSR without a middleware causes Nuxt to crash #168

Open
rizen opened this issue Jun 24, 2024 · 7 comments

Comments

@rizen
Copy link
Member

rizen commented Jun 24, 2024

Screenshot 2024-06-24 at 10 14 49 AM

@rizen
Copy link
Member Author

rizen commented Jun 25, 2024

I have learned a few things:

  • it only happens on a page that uses useVingKind().all() and that doesn't use the auth middleware
  • if i try to bring the middleware code directly into the page, it gives the error
  • if i try to bring the useCurrentUser() code directly into the middleware, it gives the error
  • if i take the code from all() and put it directly into the page, then remove the middleware, it DOES work

@rizen
Copy link
Member Author

rizen commented Jun 25, 2024

Turns out if you create a middleware that just fetches anything at all, that will also work around this problem.

export default defineNuxtRouteMiddleware(async () => {
    await $fetch(`/api/v1/test`);
});

@rizen
Copy link
Member Author

rizen commented Jun 25, 2024

This bug is caused by something in useRequestEvent() inside of Nuxt, which is used in useRest() in ving, which in turn calls useRequestHeader() which calls useRequestEvent().

The first call to useVingKind() .all() is fine in SSR, but a secondary call will crash unless it has a middleware that fetches something with $fetch() like the all-workaround middleware I have added to ving.

Alternatively, don't call all, and instead just run the code you want to run in the page rather than inside the useVingKind() composable.

I hate that we have to have this work around, but I can't figure out any other way to solve this problem. Hopefully whatever is broken inside of Nuxt will be fixed in the future.

@rizen rizen changed the title useVingKind error in TGCv which is likely a problem everywhere if you have enough data to paginate calling useVingKind().all() when doing an SSR without a middleware causes Nuxt to crash Jun 25, 2024
rizen added a commit that referenced this issue Jun 25, 2024
@rizen rizen closed this as completed Jun 25, 2024
@rizen
Copy link
Member Author

rizen commented Oct 30, 2024

It turns out that the last middleware must have something that fetches. And it's not good enough to potentially have a fetch in it, it must actually make the call. Thus caching can impede this.

@rizen
Copy link
Member Author

rizen commented Oct 30, 2024

Try to make a reproduction that can be reported to Nuxt.

@rizen rizen reopened this Oct 30, 2024
@rizen
Copy link
Member Author

rizen commented Oct 30, 2024

possibly related: nuxt/nuxt#27660

@perlDreamer
Copy link
Contributor

The users page doesn't have this problem, and it has two kinds of authentication middleware that both use useCurrentUser. You can use it as a test page for Ving by switching .search to .all and moving the page size down to something small, like 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants