-
Notifications
You must be signed in to change notification settings - Fork 62
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
fixes #756: don't make the odata request when route is being changed #1042
fixes #756: don't make the odata request when route is being changed #1042
Conversation
…anged Root cause: when user clicks on another page link, query parameter changes, which causes odataFilter watcher in SubmissionList component to send another odata request.
I wanted to look into this, because I don't understand how this is happening given how watchers work. From the Vue docs:
As you say, the navigation away from the submissions page means that the component for the page is unmounted. So why is a watcher on that page firing? I added some logging to see what was going on:
watch(router.currentRoute, ({ query: newQuery }, { query: oldQuery }) => {
+ console.log('route change: useQueryRef()'); src/router.js import { ticking } from './util/debug';
// ...
router.afterEach(() => {
console.log('route change: afterEach()');
ticking(10);
}));
watchSync(router.currentRoute, () => {
console.log('route change: watchSync()');
});
beforeUnmount() { console.log('FormSubmissions: beforeUnmount'); },
unmounted() { console.log('FormSubmissions': unmounted'); },
watch: {
$route() { console.log('route change: FormSubmissions watcher'); }
},
watch: {
+ $route() { console.log('route change: SubmissionList watcher'); },
<script setup>
...
+console.log('FormDraftTesting: created');
What's noteworthy to me is the fact that "tick" isn't logged until after I think what must be happening is that when Vue goes to unmount a component, it gives the component's watchers one last chance to react to changes. But just to throw out one last curiosity, if I call I'm glad to have looked into this though. Something similar came up with a watcher in another PR recently: #1024 (comment). |
A totally separate curiosity is that I'm actually seeing different behavior from what's described in the issue. The issue describes an error message and the fact that no submissions are shown on the draft testing page. I'm not seeing that. What I am seeing is that the Looking at the error message in the issue, it's a little puzzling to me:
That refers to this line:
An error would be thrown here if central-frontend/src/request-data/resource.js Lines 231 to 240 in eea4324
I think the error must have been due to the fact that Before #1050 came in, I'm guessing that there was a sequence along these lines:
TL;DR it's a good thing that local resources are now independent of each other. That prevents unexpected sequences like the one above and prevents errors like the one described in the issue. There's still something to fix though, which is that we should prevent the unnecessary OData request from getting sent. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to push some small changes. Before that, I wanted to leave some comments explaining a couple of my changes.
src/composables/query-ref.js
Outdated
watch(router.currentRoute, ({ query: newQuery, name: oldRouteName }, { query: oldQuery, name: newRouteName }) => { | ||
// If route is different then we don't need to set value from the query, it | ||
// will be set during setup phase | ||
if (oldRouteName !== newRouteName) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use the route path instead:
- In general, I try not to use route names to drive behavior. We need to do so in src/routes.js, but outside that, we almost never use route names.
- If the user navigates from the submissions page for one form to the submissions page for a different form (e.g., via a bookmark), then the route path will change, but the route name will not. But we still want to stop the watcher in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, comparing path
is better than name
filters.reviewState.should.eql(["'approved'"]); | ||
}) | ||
.complete() | ||
.route('/projects/1/forms/f/draft/testing') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This navigation would change the page and render a new route component. Given that, I think we should use load()
instead of loadComponent()
. That way, the route component can change.
Thanks for digging deep into this. I agree with your assessments about |
Closes central#756
What has been done to verify that this works as intended?
Added couple of tests, also manually verified that issue is fixed.
Why is this the best possible solution? Were any other approaches considered?
Root cause: when user clicks on another page link, query parameter changes, which causes odataFilter watcher in SubmissionList component to send another odata request.
If a route is being changed, hence component is being unmounted then that component should not make a new (update) request.
Another approach was to add null check for
_abortController
inresource.js:cancelRequest()
, which felt like hacky to me. or If_store
is being shared like in this case, maybe we can share the_abortController
as well; I am not fully certain about its implications though.How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
Any page that have filters like Entities data and System audit should be tested as well for regressions.
Does this change require updates to user documentation? If so, please file an issue here and include the link below.
NA
Before submitting this PR, please make sure you have:
npm run test
andnpm run lint
and confirmed all checks still pass OR confirm CircleCI build passes