content icon indicating copy to clipboard operation
content copied to clipboard

Intermittent error loading Markdown when using aws_lambda Nitro preset

Open tkgregory opened this issue 1 year ago • 1 comments

Environment

AWS Lambda Node.js 22 (not reproducable locally)

Reproduction

https://github.com/tkgregory/nuxt-content-issue

Deployed environment: https://nuxtissue.tomgregory.com/privacy — repeatedly click the links until you see the error (happens about 50% of the time).

Describe the bug

Steps to reproduce

  1. Create multiple pages in /pages that include Markdown and link to each other e.g.

/pages/privacy.vue

<template>
   <main>
       <h1 class="text-3xl font-bold mb-8">Privacy</h1>

       <div>
           <NuxtLink to="/support">Support</NuxtLink> &nbsp;
           <NuxtLink to="/privacy">Privacy</NuxtLink>
       </div>

       <ContentDoc path="/privacy" :head="false" />

   </main>
</template>

/pages/support.vue (similar as above)

  1. Configure nuxt.config.js:
  nitro: { preset: "aws_lambda" },
  1. Deploy to AWS Lambda, serving static content externally via NUXT_APP_CDN_URL
  2. View in deployed environment and repeatedly click links between pages.
  3. Intermittently observe error rendered in HTML page:
{
  "message": "You should use slots with <ContentDoc>",
  "slot": "default",
  "data": [
    {
      "_path": "/privacy",
      "_dir": "",
      "_draft": false,
      "_partial": false,
      "_locale": "",
      "title": "Privacy",
      "description": "Privacy content goes here",
      "body": {
        "type": "root",
        "children": [
          {
            "type": "element",
            "tag": "p",
            "props": {},
            "children": [
              {
                "type": "text",
                "value": "Privacy content goes here"
              }
            ]
          }
        ],
        "toc": {
          "title": "",
          "searchDepth": 2,
          "depth": 2,
          "links": []
        }
      },
      "_type": "markdown",
      "_id": "content:privacy.md",
      "_source": "content",
      "_file": "privacy.md",
      "_stem": "privacy",
      "_extension": "md"
    },
    {
      "_path": "/support",
      "_dir": "",
      "_draft": false,
      "_partial": false,
      "_locale": "",
      "title": "Support",
      "description": "Support content goes here",
      "body": {
        "type": "root",
        "children": [
          {
            "type": "element",
            "tag": "p",
            "props": {},
            "children": [
              {
                "type": "text",
                "value": "Support content goes here"
              }
            ]
          }
        ],
        "toc": {
          "title": "",
          "searchDepth": 2,
          "depth": 2,
          "links": []
        }
      },
      "_type": "markdown",
      "_id": "content:support.md",
      "_source": "content",
      "_file": "support.md",
      "_stem": "support",
      "_extension": "md"
    }
  ]
}

What I've noticed

When the error occurs, the network tab shows a different response to the XHR API call e.g. https://nuxtissue.tomgregory.com/api/_content/query/bRcR49RreS.1734656338633.json?_params=%7B%22first%22:true,%22where%22:%5B%7B%22_path%22:%22%2Fsupport%22%7D%5D,%22sort%22:%5B%7B%22_stem%22:1,%22$numeric%22:true%7D%5D%7D

The response contains an array of items:

[
	{"_path":"/privacy"},
	{"_path":"/support"}
]

(truncated for clarity)

When the error doesn't occur, the response includes a single item:

{"_path":"/support"}

(truncated for clarity)

Could be that the response contains an array of items, rather than the specific item, that's causing the issue?

What else?

  • No error responses for any network calls
  • No errors logged in browser console
  • No errors logged on backend
  • Works running locally via npm run dev
  • Works running locally via Node.js (without aws_lambda Nitro preset)
  • Works when NUXT_APP_CDN_URL is not set

Additional context

View the deployment configuration in severless.yml (uses Serverless Framework).

Logs


tkgregory avatar Dec 20 '24 01:12 tkgregory

UPDATE: I don't think my issue is related even if it's semi related as my issue was solely an issue with the way queryContent crafts it's queries leading to an error when it would add ---REGEX, I had to manually craft my where query to get it to work finally!

I am running into the same issue, it just dies before it ever even reaches out, we don't set the cdn url at all given we serve the entire site from a CDN so we can activate high TPS Wafv2 on the front and then pass through to a VPC linked AGW and then onto the lambda. Running an x-ray on the backend shows that the request is never even made, Cloudfront logs show nothing, AGW nothing, Lambda nothing.

envygeeks avatar Mar 13 '25 11:03 envygeeks