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

[BUGS] [SERVER-SIDE] [COLUMNS] It's doing extra request for each column #1317

Closed
ArseniyX opened this issue Feb 18, 2023 · 22 comments · Fixed by #1408
Closed

[BUGS] [SERVER-SIDE] [COLUMNS] It's doing extra request for each column #1317

ArseniyX opened this issue Feb 18, 2023 · 22 comments · Fixed by #1408

Comments

@ArseniyX
Copy link

ArseniyX commented Feb 18, 2023

Describe the bug
The library doing request for each columns that actually unwanted because it increase traffic and make problems to debug

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://gridjs.io/docs/examples/server-side-sort
  2. clear networks
  3. add 3 columns to the example code or copy full code below
  4. look networks
    expected: 1 request
    current: 5 requests

image

const grid = new Grid({
  sort: {
    multiColumn: false,
    server: {
      url: (prev, columns) => {
       if (!columns.length) return prev;
       
       const col = columns[0];
       const dir = col.direction === 1 ? 'asc' : 'desc';
       let colName = ['name', 'rarity', '1', '2', '3'][col.index];
       
       return `${prev}&order=${colName}&dir=${dir}`;
     }
    }
  },
  columns: [
   'Name',
   'Rarity',
   '1',
   '2',
   '3',
   {
     name: 'Image',
     width: '30%',
     sort: false,
     formatter: (img) => html(`<center><img src='${img}'/></center>`)
   }
  ],
  server: {
    url: 'https://api.scryfall.com/cards/search?q=Inspiring',
    then: data => data.data.map(card => [card.name, card.rarity, card.image_uris.small]),
    total: data => data.total_cards
  } 
});
@ArseniyX ArseniyX changed the title Doing many extra requests It's doing extra request for each column Feb 18, 2023
@ArseniyX ArseniyX changed the title It's doing extra request for each column [BUGS] [SERVER-SIDE] [COLUMNS] It's doing extra request for each column Feb 18, 2023
@rbdmorgan
Copy link

Just came across this as well. You can reproduce it with the example here:

https://gridjs.io/docs/examples/server-side-sort

image

@rbdmorgan
Copy link

It fires off the duplicate requests on load as well.

So if you have 3 columns it does 4 requests on load and then 3 requests on each sort (th click).

@rbdmorgan
Copy link

Unfortunately the server side sorting and pagination appears to be broken.

If you have both set up and click on a sort header, pagination.server() gets called 4 times and then sort.server() gets called 2 times.

The first 2 sort calls don't include the params and the pagination calls shouldn't happen at all. So depending on which call "wins" and refreshes the grid you usually end up with a grid that isn't in the correct state, plus you've hit the server 6 times rather than 1.

I guess it's a case of React duplicating/bubbling events, not as much of a problem if you're not hitting a server, so probably doesn't show up in the client side sorting and pagination.

@opheus2
Copy link

opheus2 commented Mar 16, 2023

Any update on this... In my case, without the sorting, for every column in the array, a new request is made

@crpozo
Copy link

crpozo commented Mar 22, 2023

I have the same problem. It's a great idea and library but this is an important bug. I guess adding a loading screen or something similar but this will not solved it entirely.

@crpozo
Copy link

crpozo commented Mar 22, 2023

Quick solution: Downgrade to version 5. All features seems to work fine, at least the ones I'm using.

@ArseniyX
Copy link
Author

Quick solution: Downgrade to version 5. All features seems to work fine, at least the ones I'm using.

Thanks, thats better than nothing anyway, I tried to find real solution without success

@garidium
Copy link

garidium commented Mar 27, 2023

I just ran across this as well today. I found that if I turned off search and sort options, I get one call as expected. If both of those options are enabled, I see 15 server side requests (table has 14 columns). Enabling search, with sorting disabled. I get 2 server side requests. Then adding sorting back, and removing search, it triggers 14 requests.

So in summary:

Search is adding a duplicate request
Sorting is sending a request per column

image

@miklereverie
Copy link

Any news on this? Having this exact same behavior.
I know that downgrading to version 5 fixes it, but looking for a more permanent solution.

@Marin-Matosevic
Copy link

I had faced a similar issue while using the RowSelection plugin, when attempting to select a row immediately after the page load, the selection would disappear. It was frustrating and appeared to be buggy. To overcome this, I implemented a simple workaround by creating a custom function that retrieves data from my endpoint.

Below is the implementation of the custom function, which I assigned as the data parameter inside the new Grid({})
Since is used with WordPress endpoint, I have nonce parameter but you can remove it.

async function fetchData( endpoint, nonce ) {
    try {
        const response = await fetch( endpoint, {
            headers: {
                'X-WP-Nonce': nonce,
            },
        } );
        const data = await response.json();

        return data;
    } catch ( error ) {
        console.error( error );
    }
}

and inside new Grid({})

data: await fetchData( '/wp-json/cool-endpoint/v1/data', nonce )

@mrtorks
Copy link

mrtorks commented May 16, 2023

I had faced a similar issue while using the RowSelection plugin, when attempting to select a row immediately after the page load, the selection would disappear. It was frustrating and appeared to be buggy. To overcome this, I implemented a simple workaround by creating a custom function that retrieves data from my endpoint.

Below is the implementation of the custom function, which I assigned as the data parameter inside the new Grid({}) Since is used with WordPress endpoint, I have nonce parameter but you can remove it.

async function fetchData( endpoint, nonce ) {
    try {
        const response = await fetch( endpoint, {
            headers: {
                'X-WP-Nonce': nonce,
            },
        } );
        const data = await response.json();

        return data;
    } catch ( error ) {
        console.error( error );
    }
}

and inside new Grid({})

data: await fetchData( '/wp-json/cool-endpoint/v1/data', nonce )

With this workaround, can you confirm it works with server side import, search, pagination as well as sort? If not could you provide a template for so. It would really be appreciated.

@Marin-Matosevic
Copy link

@mrtorks Yes, it works fine with pagination and sort. Not sure about search since I don't use it, but I don't see any reason why it wouldn't work.

@AleAmex
Copy link

AleAmex commented Jun 22, 2023

@rendorHaevyn
Copy link

Quick solution: Downgrade to version 5. All features seems to work fine, at least the ones I'm using.

Confirmed - downgrading to 5.0.2 prevents the request overload.

<script src="https://unpkg.com/gridjs@5.0.2/dist/gridjs.umd.js"></script>

@sabatale
Copy link

sabatale commented Aug 3, 2023

@rendorHaevyn Have you tested on 5.1.0?

@omerserif
Copy link

I am using the latest version and the problem persists.

When will the solution be?

@middle21
Copy link

I stumbled upon the same problem. I don't have sorting yet, but it happens when I use forceRender.

@vkresch
Copy link

vkresch commented Nov 13, 2023

Same issue. When making this many requests I cannot set an initial page and it just resets to zero. Is server side sorting working in 5.1.0?

@afshinm
Copy link
Member

afshinm commented Dec 30, 2023

Apologies for this issue. I have a fix for this that should address this issue and improve the overall rendering performance of the library: #1408

@afshinm
Copy link
Member

afshinm commented Jan 14, 2024

A new version is now available. Please try v6.1.0 https://www.npmjs.com/package/gridjs

@charlesmudy
Copy link

@afshinm this is still happening with v6.2.0 as of today. Not sure why and the fix to this. We are using handle option with alert, now causing the application to alert multiple times.

@RegistrosTI
Copy link

I confirm that this issue still exists in version 6.2.0. When the sort server is configured, it makes a fetch for every column.

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 a pull request may close this issue.