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

CompoundFilter.toJSON() throws when FunctionFilter present #3929

Open
ghsolomon opened this issue Feb 25, 2025 · 2 comments
Open

CompoundFilter.toJSON() throws when FunctionFilter present #3929

ghsolomon opened this issue Feb 25, 2025 · 2 comments
Labels

Comments

@ghsolomon
Copy link
Contributor

CompoundFilter.toJSON calls toJSON on its child filters:
https://github.com/xh/hoist-react/blob/c94ce756e930e6b32bf8d67271795b5db7b1892d/data/filter/CompoundFilter.ts#L70C1-L76C6

This will throw in the presence of a FunctionFilter since FunctionFilter does not have a toJSON method (functions are not serializable).

To fix, function filters should be omitted. Could consider flattening afterward as well.

@ghsolomon ghsolomon added the data label Feb 25, 2025
@amcclain
Copy link
Member

My concern about omitting is that you end up with an incomplete / inaccurate representation of the filter. I don't know that it would be a good idea to build that in - could result in bad surprises.

Although we could be throwing a more structured error, up front, in that method, if any function filters are nested within.

@ghsolomon
Copy link
Contributor Author

Yeah a more structured error would work as well. Currently, invoking toJSON on a CompoundFilter containing FunctionFilters throws in a bit of a confusing way:

Example:
JSON.stringify(filterModel.filter) can throw this exception:

Uncaught: TypeError: f.toJSON is not a function
    at CompoundFilter.ts:51:53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants