Skip to main content

Why aren't Vue prop changes triggering reactivity in my bundled component?

I've been troubleshooting this issue for a while now and I'm running out of ideas. I hope some fresh eyes can give me a better perspective.

In short: I have several computed properties in a component that are not reacting to changes in props only after bundling. Before bundling, the computed properties work exactly as expected.

Here's the relevant bits of code. For context, this is part of a paginated data table component.

setup(props) {
    props = reactive(props);
   
    const isNextDisabled = computed(() => props.index + props.pageSize >= props.totalSize

    const rangeUpperBound = computed(() => {
        let upperBound = props.index + props.pageSize;
        if (upperBound > props.totalSize) {
            upperBound = props.totalSize;
        }
        return upperBound;
    });

    return {
        isNextDisabled,
        upperBound,
    }
}

I'm using Storybook.js to develop this component as part of a library. I'm also trying to simulate async data fetching, so my props are initially null values and then I have a setTimeout function that loads some data from a file after 1.5 seconds. In other words, my props are definitely being updated and I expect my computed properties to be evaluated twice (once at first render, again when the props they depend on are updated).

When I'm developing the components with the vanilla npm run storybook command everything works as expected. All the computed properties are updated properly once the timeout finishes, and the component renders correctly. I hit snags when I bundle my components.

I'm using Vue CLI's default configuration to bundle things, my command is:

vue-cli-service build --target lib --name copper-vue src/index.js

Here is that src/index.js file:

export { default as DataTable } from "./components/DataTable/DataTable";

Here's my problem: When I use the component from the bundled file none of the computed properties in my component are updated when the props are updated after the setTimeout. I've verified with logging statements and a debugger that the computed properties are only evaluated once when the component first renders, and they seem to completely ignore the fact that the props they depend on have updated. I've also verified this happens with a watchEffect call I added during my testing.

I've been testing this by importing the bundled component, rather than the component from my .vue file, in my Storybook story like so:

// Shortcut story in question:

<template>
  <span>This story waits 1.5 seconds before it loads any data, as a rudimentary way to simulate async data fetching.</span>
  <data-table
    :data="dataSubset"
    :columns="columns"
    @editRow="handleEditRow"
    paginate
    :index="index"
    :page-size="pageSize"
    :total-size="totalSize"
    @change-page="getNewPage"
    @change-page-size="changePageSize"
  />
</template>

<script>
// This is the import to use the component from the SFC
// import DataTable  from "./DataTable.vue";

// Here's how I import the component from the bundled file which causes issues
import { DataTable } from "../../../dist/copper-vue.common";

...
</script>

Other relevant details:

  • This bug happens in both Chrome and Firefox
  • I'm using Vue 3.2.8, Storybook 6.3.12
  • Running/bundling on a 2020 M1 Macbook pro

Things I might try next:

  • Walking back some Vue versions to see if 3.1 works, 3.0 works, etc

Is there something about the reactive APIs that I'm doing incorrectly here? I'm completely baffled why things work as expected when running in a "dev" mode and not when bundled using Vue CLI. Any tips are appreciated.

Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW

Comments

Popular posts from this blog

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to split a rinex file if I need 24 hours data

Trying to divide rinex file using the command gfzrnx but getting this error. While doing that getting this error msg 'gfzrnx' is not recognized as an internal or external command Trying to split rinex file using the command gfzrnx. also install'gfzrnx'. my doubt is I need to run this program in 'gfzrnx' or in 'cmdprompt'. I am expecting a rinex file with 24 hrs or 1 day data.I Have 48 hrs data in RINEX format. Please help me to solve this issue. source https://stackoverflow.com/questions/75385367/how-to-split-a-rinex-file-if-i-need-24-hours-data