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

Prevent JSON parse error #827

Merged
merged 2 commits into from
Mar 11, 2021
Merged

Prevent JSON parse error #827

merged 2 commits into from
Mar 11, 2021

Conversation

TheJaredWilcurt
Copy link
Collaborator

Users can pass in { enabled: true } as the sortOptions, which means initialSortBy would be undefined and JSON.parse throws an error when you hand it undefined. So we need to default the value if it is not present.

Users can pass in `{ enabled: true }` as the sortOptions, which means `initialSortBy` would be `undefined` and `JSON.parse` throws an error when you hand it `undefined`. So we need to default the value if it is not present.
@@ -1582,7 +1582,7 @@ export default {

initializeSort() {
const { enabled, initialSortBy, multipleColumns } = this.sortOptions;
const initSortBy = JSON.parse(JSON.stringify(initialSortBy));
const initSortBy = JSON.parse(JSON.stringify(initialSortBy || {}));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If initialSortBy is undefined default to an empty object to prevent JSON.parse(undefined) error from throwing.

@TheJaredWilcurt
Copy link
Collaborator Author

@xaksis Updating to the latest version and most of my tests broke with super cryptic error messages. Took a while to track this down, but it was a very easy fix.

@pgrantmartello
Copy link

I came to dig into this same issue. Thanks for fixing it.

@xaksis xaksis merged commit c26940a into master Mar 11, 2021
@xaksis
Copy link
Owner

xaksis commented Mar 11, 2021

Thanks @TheJaredWilcurt !

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

Successfully merging this pull request may close these issues.

3 participants