question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

item-provider is called twice?

See original GitHub issue

Describe the bug

The item provider for b-table is called twice.

Steps to reproduce the bug

This is the b-table:

                <b-table
                        :items="itemProvider"
                        :busy.sync="isBusy"
                        :fields="fields"
                        :sort-by.sync="sortBy"
                        :sort-desc.sync="sortDesc"
                        :striped="true"
                        :bordered="true"
                        :current-page="pagination.current_page"
                        :per-page="pagination.per_page"
                        class="card-table">

                    <template slot="status" slot-scope="data">
                        <b-badge variant="outline-success" v-if="data.item.status === 'active'">Active</b-badge>
                        <b-badge variant="outline-danger" v-if="data.item.status === 'inactive'">Inactive</b-badge>
                    </template>
                </b-table>

Method:

itemProvider () {
			this.isBusy = true;
                        //if I add console.log("Test"); here, it's displayed twice, too.
			let promise = axios.get ('/users/index?page=' + this.pagination.current_page);

			return promise.then (resp => {
				let items = resp.data.data;
				this.pagination.current_page = resp.data.current_page;
				this.pagination.last_page = resp.data.last_page;
				this.pagination.per_page = resp.data.per_page;
				this.pagination.total = resp.data.total;
				this.isBusy = false;

				return items
			}).catch (error => {
				this.isBusy = false;
				return [];
			})
		},

Expected behavior

Route is called only once.

Versions

Libraries:

  • BootstrapVue: 2.0.0-rc.1
  • Bootstrap: 4.3.1
  • Vue: 2.6.6

Environment:

  • Device: MacBook
  • OS: macOS Mojave
  • Browser: Safari
  • Version: 12.1 (14607.1.40.1.4)

Additional context

Bildschirmfoto 2019-05-06 um 10 45 37

I just found out that the double-call is removed if I remove :current-page="pagination.current_page" ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tmorehousecommented, May 6, 2019

In your case, it is probably because you are setting the pagination parameters in the provider (in the then), which is triggering b-table to re-fetch the data, as the parameters (i.e. per page, current_page, etc) are being updated with values that might be different (i.e. a number as string vs a number)

0reactions
arthurshlaincommented, Feb 14, 2020

One solution, when you use props to rewrite default sortBy, sortDesc and other variables.

Use condition <b-table v-if="tableReady" ...> in template. Add tableReady: false to your data object. Add this.tableReady = true; after code that sets your props.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SwiftUI onDrag being called twice - Stack Overflow
I'm implementing Drag & Drop using SwiftUI. The problem I'm facing is that onDrag is called twice: The first time is when long...
Read more >
getTimeline called twice on load | Apple Developer Forums
When I run my widget from xcode I see getTimeline is called twice for some reason. It's called the first time, then after...
Read more >
Difference Between Stub, Mock, and Spy in Spock Framework
So generally, this line says: itemProvider.getItems will be called once with ['item-'id'] argument and return given array. We already know that ...
Read more >
Adding support for multiple windows to your iPadOS app
The default scene configuration is called Default Configuration and uses the $(PRODUCT_MODULE_NAME).SceneDelegate object to set up its scene and ...
Read more >
The Complete Guide of PHPicker in iOS 14 - AppCoda
Each one of them contains a property called itemProvider , which is an ... You can do that multiple times; all of them...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found