Skip to content

fix(client-vue3): Avoid Maximum recursive updates exceeded #9548

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions packages/cubejs-client-vue3/src/QueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,19 +381,27 @@ export default {
};

this.chartType = chartType || this.chartType;
this.pivotConfig = ResultSet.getNormalizedPivotConfig(
let pivot = ResultSet.getNormalizedPivotConfig(
validatedQuery,
pivotConfig !== undefined ? pivotConfig : this.pivotConfig
);
this.copyQueryFromProps(validatedQuery);
if (!equals(pivot, this.pivotConfig)) {
this.pivotConfig = pivot;
}

if (!areQueriesEqual(this.prevValidatedQuery, validatedQuery)) {
this.copyQueryFromProps(validatedQuery);
}
}

// query heuristics should only apply on query change (not applied to the initial query)
if (this.prevValidatedQuery !== null) {
this.skipHeuristics = false;
}

this.prevValidatedQuery = validatedQuery;
if (!areQueriesEqual(this.prevValidatedQuery, validatedQuery)) {
this.prevValidatedQuery = validatedQuery;
}
return validatedQuery;
},
},
Expand Down
116 changes: 116 additions & 0 deletions packages/cubejs-client-vue3/tests/unit/QueryBuilder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,80 @@ describe('QueryBuilder.vue', () => {
expect(wrapper.vm.pivotConfig).toEqual(expectedPivotForLine);
expect(wrapper.vm.chartType).toBe('line');
});
it('should not reassign validatedQuery if it has not changed', async () => {
const cube = createCubeApi();
jest
.spyOn(cube, 'request')
.mockImplementation(fetchMock(load))
.mockImplementationOnce(fetchMock(meta));

const wrapper = shallowMount(QueryBuilder, {
propsData: {
cubeApi: cube,
query: {
measures: ['Orders.count'],
timeDimensions: [
{
dimension: 'Orders.createdAt',
},
],
},
},
});

const initialValidatedQuery = {
measures: ['measure1'],
dimensions: ['dimension1'],
};
wrapper.setData({ prevValidatedQuery: initialValidatedQuery });

wrapper.setData({
measures: [{ name: 'measure1' }],
dimensions: [{ name: 'dimension1' }],
});

await wrapper.vm.$nextTick();

expect(wrapper.vm.prevValidatedQuery.measures).toEqual(initialValidatedQuery.measures);
expect(wrapper.vm.prevValidatedQuery.dimensions).toEqual(initialValidatedQuery.dimensions);
});

it('should reassign validatedQuery if it has changed', async () => {
const cube = createCubeApi();
jest
.spyOn(cube, 'request')
.mockImplementation(fetchMock(load))
.mockImplementationOnce(fetchMock(meta));

const wrapper = shallowMount(QueryBuilder, {
propsData: {
cubeApi: cube,
query: {
measures: ['Orders.count'],
timeDimensions: [
{
dimension: 'Orders.createdAt',
},
],
},
},
});
const initialValidatedQuery = {
measures: ['measure1'],
dimensions: ['dimension1'],
};
wrapper.setData({ prevValidatedQuery: initialValidatedQuery });

wrapper.setData({
measures: [{ name: 'measure2' }],
dimensions: [{ name: 'dimension1' }],
});

await wrapper.vm.$nextTick();

expect(wrapper.vm.prevValidatedQuery.measures).not.toEqual(initialValidatedQuery.measures);
expect(wrapper.vm.prevValidatedQuery.dimensions).toEqual(initialValidatedQuery.dimensions);
});
});
describe('orderMembers', () => {
it('does not contain time dimension if granularity is set to none', async () => {
Expand Down Expand Up @@ -1001,6 +1075,48 @@ describe('QueryBuilder.vue', () => {
])
);
});
it('calls copyQueryFromProps if query is changed', async () => {
const cube = createCubeApi();
jest
.spyOn(cube, 'request')
.mockImplementation(fetchMock(load))
.mockImplementationOnce(fetchMock(meta));

const copyQueryFromProps = jest.spyOn(QueryBuilder.methods, 'copyQueryFromProps');

const wrapper = shallowMount(QueryBuilder, {
propsData: {
cubeApi: cube,
query: {
measures: ['Orders.count'],
timeDimensions: [
{
dimension: 'Orders.createdAt',
},
],
},
},
});
await flushPromises();

await wrapper.vm.$nextTick();
expect(wrapper.vm.measures.length).toEqual(1);
expect(wrapper.vm.measures[0].name).toEqual('Orders.count');

await wrapper.vm.$nextTick();

expect(copyQueryFromProps).toHaveBeenCalled();
expect(copyQueryFromProps).toHaveBeenCalledTimes(1);
const initialValidatedQuery = {
measures: ['measure1'],
dimensions: ['dimension1'],
};
wrapper.setData({ prevValidatedQuery: initialValidatedQuery });
await wrapper.vm.$nextTick();

expect(copyQueryFromProps).toHaveBeenCalledTimes(2);
copyQueryFromProps.mockRestore();
});
});
});
});
Loading