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

[9.5.2] The query string doesn't cleanup undefined value #16147

Closed
nghiepdev opened this issue Aug 13, 2020 · 2 comments · Fixed by #16608
Closed

[9.5.2] The query string doesn't cleanup undefined value #16147

nghiepdev opened this issue Aug 13, 2020 · 2 comments · Fixed by #16608
Assignees
Milestone

Comments

@nghiepdev
Copy link
Contributor

nghiepdev commented Aug 13, 2020

Bug report

Describe the bug

Navigating router via push:

router.push({
  pathname: "/page-a",
  query: {
    param1: "ok",
    param2: undefined
  }
})
// /pages/page-2
const router = useRouter();

console.log(router.query);

Result

{
  param1: "ok",
  param2: "undefined"
}

In the page-a: The param2 is an undefined string value.

Expected behavior

Result

{
  param1: "ok"
}

The param2 should be an undefined value.

System information

  • OS: [macOS]
  • Browser (if applies) [chrome]
  • Version of Next.js: [9.5.2]
  • Version of Node.js: [14]

Additional context

#15378

@Timer Timer added this to the 9.x.x milestone Aug 13, 2020
@Timer Timer modified the milestones: 9.x.x, iteration 7 Aug 13, 2020
@Timer Timer added the point: 2 label Aug 13, 2020
@Timer Timer modified the milestones: 9.x.x, iteration 7 Aug 13, 2020
@Janpot
Copy link
Contributor

Janpot commented Aug 26, 2020

Keep in mind that in next@<9.5, the result would be

{
  param1: "ok",
  param2: ""
}

and not

{
  param1: "ok"
}

edit:

In fact, been testing values for query from pre vs post #15378. and the results are quite different, i.e.

  router.push({
      pathname: "/query",
      query: {
        param1: '',
        param2: undefined,
        param3: null,
        param4: 0,
        param5: false,
        param6: [],
        param7: {},
        param8: NaN,
        param9: new Date(1234),
        param10: /hello/
      }
    })

pre #15378 this results in:

{
  "param1": "",
  "param2": "",
  "param3": "",
  "param4": "0",
  "param5": "false",
  "param7": "",
  "param8": "",
  "param9": "",
  "param10": ""
}

post #15378 we get:

{
  "param1": "",
  "param2": "undefined",
  "param3": "null",
  "param4": "0",
  "param5": "false",
  "param7": "[object Object]",
  "param8": "NaN",
  "param9": "Thu Jan 01 1970 01:00:01 GMT+0100 (Central European Standard Time)",
  "param10": "/hello/"
} 

looks like these only agree on "", 0, false and [] .

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants