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

[Bug] Error serializing .pagination.currentPage #510

Open
johnd-dc3 opened this issue Jul 11, 2023 · 0 comments
Open

[Bug] Error serializing .pagination.currentPage #510

johnd-dc3 opened this issue Jul 11, 2023 · 0 comments

Comments

@johnd-dc3
Copy link

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!

@johnd-dc3 johnd-dc3 changed the title [Bug] [Bug] Error serializing .pagination.currentPage Jul 11, 2023
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

1 participant