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

When navigating back to /:Slug the fetch queryContent(route.path).find() fails with FetchError: 404 Document not found! #1656

Closed
JasonLandbridge opened this issue Nov 4, 2022 · 3 comments

Comments

@JasonLandbridge
Copy link
Sponsor

Environment

  • Operating System: Linux
  • Node Version: v18.11.0
  • Nuxt Version: 3.0.0-rc.13
  • Nitro Version: 0.6.1
  • Package Manager: npm@8.19.2
  • Builder: vite
  • User Config: srcDir, ssr, target, content, css, build, vite, modules, components, alias
  • Runtime Modules: @nuxt/content@2.2.1, @pinia/nuxt@0.4.3, ()
  • Build Modules: -

Reproduction

Steps to reproduce:

  1. Got to https://www.plexripper.rocks/announcements
  2. Open the F12 inspector console, and see there are no errors
  3. Click on the "Guides" menu item on the top.
  4. Then go back by clicking on the "Announcement" menu item at the top
  5. Now the fetch command for that page fails, the page however is displayed correctly

Describe the bug

Hi there,

Project link: https://github.com/PlexRipper/Docs

Here is a weird issue, initially loading the page https://www.plexripper.rocks/announcements works perfectly. However, when navigating away, and then returning again, will make that same fetch request fail. I have been debugging this for a few hours now, trying to pin the problem down and re-creating a stack-blitz but I can't reproduce it there.

The website is open source and the culprit can be found here:

Code link

const currentPage: IAnnouncement[] = await queryContent(route.path).find() as IAnnouncement[]

I found this similar issue #1565, which was then fixed in #1612. This was however only for .findOne(). Maybe the .find() was overlooked as a possible problem area as well?

I also found this similair issue: #1513
I tried the fix from there by adding a .where() in between and the error was still there

Please let me know if I should provide more information, thanks!

Additional context

The first correct API call is the following:

http://localhost:4000/api/_content/query?_params={%22where%22:[{%22_path%22:%22--REGEX+/^%5C%5C/announcements/%22}],%22sort%22:[{%22_file%22:1,%22$numeric%22:true}]}&previewToken

Then on navigating back, the following API call is created which fails:

http://localhost:4000/api/_content/query?_params={%22where%22:[{%22_path%22:%22/announcements%22}],%22first%22:true,%22sort%22:[{%22_file%22:1,%22$numeric%22:true}]}&previewToken

The main difference I'm spotting here is the missing --REGEX+ in the API call that fails. Which I tracked down to query.ts. Inside the _params: jsonStringify(params) call, the Regex is supposed to be added here in the regExpReplacer. Maybe something goes wrong here, hopefully it helps narrowing down the issue.

Logs

Error:

GET http://localhost:4000/api/_content/query?_params={%22where%22:[{%22_path%22…rst%22:true,%22sort%22:[{%22_file%22:1,%22$numeric%22:true}]}&previewToken 404 (Document not found!) ohmyfetch.d1948a88.mjs?v=b2b5ab98:144 

$fetchRaw2					@ohmyfetch.d1948a88.mjs?v=b2b5ab98:144
$fetch2						@ohmyfetch.d1948a88.mjs?v=b2b5ab98:173
(anonymous)					@query.mjs?v=b2b5ab98:27
findOne						@query.mjs?v=b2b5ab98:29
pageQuery					@documentDriven.mjs?v=b2b5ab98:111
(anonymous)					@documentDriven.mjs?v=b2b5ab98:141
refresh						@documentDriven.mjs?v=b2b5ab98:141
(anonymous)					@documentDriven.mjs?v=b2b5ab98:181
fn						@nuxt.mjs?v=b2b5ab98:138
callWithNuxt					@nuxt.mjs?v=b2b5ab98:143
(anonymous)					@router.mjs?v=b2b5ab98:106
await in (anonymous) (async)
(anonymous)					@vue-router.mjs:1997
(anonymous)					@vue-router.mjs:1969
(anonymous)					@vue-router.mjs:3568
Promise.then (async)
(anonymous)					@vue-router.mjs:3568
runGuardQueue					@vue-router.mjs:3568
(anonymous)					@vue-router.mjs:3245
Promise.then (async)
navigate					@vue-router.mjs:3238
pushWithRedirect				@vue-router.mjs:3166
push						@vue-router.mjs:3099
navigate					@vue-router.mjs:2189
onClick						@VBtn.tsx:161
callWithErrorHandling				@runtime-core.esm-bundler.js:155
callWithAsyncErrorHandling			@runtime-core.esm-bundler.js:164
invoker						@runtime-dom.esm-bundler.js:339
Copy link
Member

farnabaz commented Nov 8, 2022

When you enable document-driven mode, Module tries to load content that have same path as your page, and since you don't have index.md in the announcements directory, it will raise a 404 error.

You can disable document-driven per page in situations like this. put this snippet in annoucement/index.vue

definePageMeta({
  documentDriven: false
})

@JasonLandbridge
Copy link
Sponsor Author

Thank you so much! It works perfectly now!

@iartist93
Copy link

Thank you so much! This worked for me too.

Add this snippet to every other page under /pages that's not related to Nuxt Content!

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

3 participants