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

[Performance]Too many request to API endpoint when using ReferenceInput and ReferenceArrayInput #3108

Closed
tunglt1810 opened this issue Apr 8, 2019 · 10 comments · Fixed by #3252

Comments

@tunglt1810
Copy link

tunglt1810 commented Apr 8, 2019

Hi, first words, thanks for your awesome project.

I have use ReferenceInput and ReferenceArrayInput in my form like this:

<ReferenceArrayInput source="parentRoleIds" reference="roles">
                <CheckboxGroupInput optionValue="id" optionText="name"/>
</ReferenceArrayInput>

But when i check the checkbox, this component send too much request to server. I think it's not necessary.

ReferenceInput

After the input mounted and load reference data. It's should be not need load reference data again when changing the value of input

@djhi
Copy link
Contributor

djhi commented Apr 8, 2019

Hi, and thanks for your question. As explained in the react-admin contributing guide, the right place to ask a "How To" question, get usage advice, or troubleshoot your own code, is StackOverFlow.

This makes your question easy to find by the core team, and the developer community. Unlike Github, StackOverFlow has great SEO, gamification, voting, and reputation. That's why we chose it, and decided to keep GitHub issues only for bugs and feature requests.

So I'm closing this issue, and inviting you to ask your question at:

http://stackoverflow.com/questions/tagged/react-admin

And once you get a response, please continue to hang out on the react-admin channel in StackOverflow. That way, you can help newcomers and share your expertise!

@djhi djhi closed this as completed Apr 8, 2019
@tunglt1810 tunglt1810 changed the title Too many request to API endpoint when using ReferenceInput and ReferenceArrayInput [Performance]Too many request to API endpoint when using ReferenceInput and ReferenceArrayInput Apr 8, 2019
@tunglt1810
Copy link
Author

Hi @djhi , it's my mistake of using "word". I've update this post

@djhi djhi reopened this Apr 8, 2019
@djhi
Copy link
Contributor

djhi commented Apr 8, 2019

Thanks for reporting this. If you are able to illustrate the bug or feature request with an example, please provide a sample application via one of the following means:

@fzaninotto
Copy link
Member

I can confirm the problem on the simple example:

  • Open PostEdit

  • Change tags input to use CheckboxGroupInput:

                <ReferenceArrayInput
                    reference="tags"
                    source="tags"
                    filter={{ published: true }}
                >
                    <CheckboxGroupInput optionText="name" />
                </ReferenceArrayInput>

Each click on a checkbox calls the dataProvider, as seen on this screenshot:

Capture d’écran du 2019-04-19 12-22-05

@fzaninotto
Copy link
Member

The problem comes from ReferenceArrayInputController, who fetches references each time the value changes:

componentWillReceiveProps(nextProps: Props & EnhancedProps) {
let shouldFetchOptions = false;
if (
(this.props.record || { id: undefined }).id !==
(nextProps.record || { id: undefined }).id
) {
this.fetchReferencesAndOptions(nextProps);
} else if (this.props.input.value !== nextProps.input.value) {
this.fetchReferences(nextProps);
} else {
if (!isEqual(nextProps.filter, this.props.filter)) {
this.params = { ...this.params, filter: nextProps.filter };
shouldFetchOptions = true;
}
if (!isEqual(nextProps.sort, this.props.sort)) {
this.params = { ...this.params, sort: nextProps.sort };
shouldFetchOptions = true;
}
if (nextProps.perPage !== this.props.perPage) {
this.params = {
...this.params,
pagination: {
...this.params.pagination,
perPage: nextProps.perPage,
},
};
shouldFetchOptions = true;
}
}
if (shouldFetchOptions) {
this.fetchOptions();
}
}

I'm not sure we can change that, as it's necessary to force fetching of actual values when the parent updates...

@fzaninotto
Copy link
Member

The best we could do is first check if the values aren't in the options, and only then trigger a fetchReferences.

@fargito
Copy link
Contributor

fargito commented May 20, 2019

Hello !

Thanks for the project :)
I'm trying to solve the issue, I will try to get back tomorrow with something ;)

@boutdemousse
Copy link

Same behavior with the 2.9.3 version.
Tested using the same method and updating the package.json.

I have the same problem on my side with text inputs.
A request is sent for each key press and when the element lose the focus which makes quite a ton of requests in a very short period of time and it also makes the UI is very laggy.

@tunglt1810
Copy link
Author

Same behavior with the 2.9.3 version.
Tested using the same method and updating the package.json.

I have the same problem on my side with text inputs.
A request is sent for each key press and when the element lose the focus which makes quite a ton of requests in a very short period of time and it also makes the UI is very laggy.

me too

@x5engine
Copy link

@fzaninotto actually this componentWillReceiveProps is deprecated better move to componentDidUpdate for a side effect.

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

Successfully merging a pull request may close this issue.

6 participants