Skip to content

[Bug] Error serializing .pagination.currentPage #510

@johnd-dc3

Description

@johnd-dc3

Bug Report

Describe the bug

On initializing the project, I receive the following error (full error statement below)

Error: Error serializing `.pagination.currentPage` returned from `getStaticProps` in "/".
Reason: `undefined` cannot be serialized as JSON. Please use `null` or omit this value.

Note that a simple solution is to remove the undefined value from pagination.current page in lib/posts.js. (This fixed the problem, but I'm not sure how to open a pull request!) Example fix (from posts.js):

  if (typeof page === 'undefined' || isNaN(page)) {
    page = 1;
  } else if (page > pagesCount) {
    return {
      posts: [],
      pagination: {
        currentPage,
        pagesCount,
      },
    };
  }

Is this a regression?

Not sure, have not tried on previous version

Steps To Reproduce the error

  1. download the project via npm
  2. Connect to Wordpress project via WPGraphQL
  3. Wordpress project is on a local server for development. Using XAMPP locally.
  4. Run npm run dev and I get the following error:

Server Error
Error: Error serializing .pagination.currentPage returned from getStaticProps in "/".
Reason: undefined cannot be serialized as JSON. Please use null or omit this value.

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
isSerializable
file:///C:/html/dc3-headless-cms/node_modules/next/dist/lib/is-serializable-props.js (52:19)

file:///C:/html/dc3-headless-cms/node_modules/next/dist/lib/is-serializable-props.js (59:66)
Array.every

isSerializable
file:///C:/html/dc3-headless-cms/node_modules/next/dist/lib/is-serializable-props.js (56:39)

file:///C:/html/dc3-headless-cms/node_modules/next/dist/lib/is-serializable-props.js (59:66)
Array.every

isSerializable
file:///C:/html/dc3-headless-cms/node_modules/next/dist/lib/is-serializable-props.js (56:39)
isSerializableProps
file:///C:/html/dc3-headless-cms/node_modules/next/dist/lib/is-serializable-props.js (79:12)
renderToHTML
file:///C:/html/dc3-headless-cms/node_modules/next/dist/server/render.js (493:118)
process.processTicksAndRejections
node:internal/process/task_queues (95:5)
async doRender
file:///C:/html/dc3-headless-cms/node_modules/next/dist/server/base-server.js (1029:34)
async cacheEntry.responseCache.get.incrementalCache.incrementalCache
file:///C:/html/dc3-headless-cms/node_modules/next/dist/server/base-server.js (1159:28)
async
file:///C:/html/dc3-headless-cms/node_modules/next/dist/server/response-cache/index.js (99:36)

Expected behaviour

Project would open on http://localhost:3000 without issue

CodeSandbox or Live Example of Bug

Screenshot or Video Recording

Your environment

  • OS: Windows 11 Pro, Version 22H2
  • Node version: v18.12.0
  • Npm version: 8.19.2
  • Browser name and version: Chrome, Version 114.0.5735.199

Additional context

thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions