vue-good-table icon indicating copy to clipboard operation
vue-good-table copied to clipboard

on-per-page-change is called twice if perPage is set following the first event

Open Ariane-B opened this issue 3 years ago • 0 comments

Issue Type (delete the irrelevant ones)

  • [x] Bug

Specs

What version are you using?

  • 2.21.11

What browser?

  • Firefox 97.0 for Windows

Expected Behavior

Even if the event listener for @on-per-page-change sets the value that's assigned to perPage, especially not to the same value, it should only trigger the event once.

Actual Behavior

It behaves like a watcher for some reason. It's fired once when the user changes the number of items per page, and once again when GET parameters are updated following the event.

The watcher seems to be here:

https://github.com/xaksis/vue-good-table/blob/889962c5b67f5bb621caa0a9bf0b3852d4199235/dist/vue-good-table.esm.js#L2411

I'm not sure what the solution is, but I've got a strong feeling that changing the props on my side shouldn't trigger a feedback loop like this.

Steps to Reproduce the Problem

Please detail your steps here

  1. Change the number of items per page while keeping a close eye on the console
  2. See that onPerPageChange is fired twice.
  3. On HTML's line 20, use DEFAULT_API_GET_DATA_PARAMS.perPage instead.
  4. Now onPerPageChange is only fired once.

An alternative workaround would be to run a for...in loop on all paramsToSet in setApiGetParamsAndFetchRows and, for each parameter, compare it to the current value and only change it if it's different.

...But whichever workaround you choose, it's still really weird that the event is triggered twice if you do things normally.

jsfiddle

https://jsfiddle.net/dywr30ek/17/

Ariane-B avatar Feb 16 '22 00:02 Ariane-B