Fix infinite loop when creating filters #3061
Labels
No Label
area/internal-code
changes requested
confirmed
dependencies
duplicate
good first issue
help wanted
hosting
invalid
kind/bug
kind/feature
question
wontfix
No Milestone
No project
No Assignees
4 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: vikunja/frontend#3061
Loading…
Reference in New Issue
No description provided.
Delete Branch "ThatHurleyGuy/frontend:fix-loop"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Preamble
Just setup an instance of Vikunja for my wife and I to keep track of our TODO lists. Really impressed with it so far, kudos for building out such an awesome app for this. I'm more of a systems/database engineer, so my frontend experience is pretty lacking. There may very well be a better solution to this.
System Environment
Firefox 109.0.1 osx 13.1, my timezone is America/Mountain (UTC-6).
Repro Steps
now + 12h
Expected
The date field populates with the text as it's typed in
Observed Behavior
The browser tab hangs in an infinite loop. I checked out the code to run it locally and saw that in the console I got the real fun
Maximum recursive updates exceeded in component <card>. This means you have a reactive effect that is mutating its own dependencies and thus recursively triggering itself. Possible sources include component template, render function, updated hook or watcher source function.
message. What seems to be happening is:From
field is null, so it defaults to Jan 1 1970prepare
function here, and because the date object is in the user's local timezone which is -6 it's technically the day before, Dec 31 1969Proposed Solution
Rather than putting in a truncated version of the date/time with
startDate.getDate
, use the iso formatted version which includes the timezone data. I have no idea if this has ramifications elsewhere in the app, but it solves the problems I was seeing.8ea821667b
to7e532ab680
@konrad Sorry for the super verbose PR description, wanted to try and give plenty of the debugging info I ran into. Let me know if there's anything else I can help do try and fix this!
Hi ThatHurleyGuy!
Thank you for creating a PR!
I've deployed the changes of this PR on a preview environment under this URL: https://3061-fix-loop--vikunja-frontend-preview.netlify.app
You can use this url to view the changes live and test them out.
You will need to manually connect this to an api running somehwere. The easiest to use is https://try.vikunja.io/.
Have a nice day!
@ -427,10 +427,10 @@ function prepareDate(filterName, variableName) {
const endDate = new Date(params.value.filter_value[foundDateEnd])
filters.value[variableName] = {
dateFrom: !isNaN(startDate)
Good catch with that error!
When looking at the mistake I think that the
!isNaN(startDate)
line is the broken one, because:What that line should actually do is to check if the Date is a valid one, which it is not! (it is [!] by the ECMAScript definition because
new Date()
coerces to type Number if it's not a string—didn't know that myself)We could check that with some helper function. E.g.
I established for myself the convention that a 'kebab date' is a date string in the format
2023-02-07
. I only found out later that this is also a valid ISO date string that has only day precision and lacks a time zone. Still haven't found a better name though. MaybeISODateStringWithDayPrecision
🤷♂️ ?We want to replace that filter logic anyway (see that pull request. Again has to be rebased...)
For now I would be fine to replace the
!isNaN
-part with a better check like the one above.@konrad Anything to add here?
Ah yeah that's a good idea, I can take a stab at changing the
isNaN
check to something like you suggested here later todayActually, I take that back. I don't think the
isNaN
check is related here, although I think you're right there's a subtle bug lurking there. The real issue is the time parsing and how timezones impact that. When I'm seeing this infinite loop (in timezone America/Denver, UTC-7) the date is totally valid and notnan
. The issue is caused by the timezone drift. Here's a simple example from my browser's javascript console:Each time this page renders, the date gets set back one day earlier which retriggers the formatting, repeat. However, if I set my system's timezone to Germany this drift doesn't happen because it's a positive offset (probably why others haven't seen this occurring):
So unless I'm missing something, the
isNaN
check is unrelated here, the issue is timezones (the bane of all programmers existence).The only solutions I can think of are:
getUTC{FullYear,Month,Date}
to ensure it's always the same timezone date used:Interesting find. I like version 3. Mostly because it would align best with the current implementation.
For the future it would probably be best if we would use ISO dates everywhere, but for that it would make sense to check all the other parts of the app that use date. Might as well be that I'm missing some insight for my conclusion.
What do you think @konrad?
Updated the PR to use UTC dates
@dpschen ISO dates are a good idea, would make it consistent with what the api does already.
What version did you encounter the bug on? I just tried this on try (last unstable build), but didn't manage to reproduce it. I do remember though having fixed this error in the past.
@konrad This happens on every version I tried, including main/HEAD. What timezone did you test it in? Like I mentioned in the PR description, it consistently happens to me with any negative offset timezones
7e532ab680
to4527a66c83
I'm in UTC+1 (Germany). I set the Browser to UTC-7 but could not reproduce your example:
Is this still relevant?
@ThatHurleyGuy Looks like the browser hanging is not an issue but the date input does not seem to do what it should.
Do you want to modify your PR?
4527a66c83
toe08b887048
e08b887048
to5c08442837
@konrad Sorry for the slowww response. I just updated the PR to be up to date with main. Uploaded screenshots for what I'm seeing on main vs how it looks on my branch/machine. Main definitely still has the loop (in dev there's a guard that prevents it from looping more than 100 times and then spits out that message). The result is "End Date" with the verbose date of January 1st 1970 minus 100 iterations of the loop subrracting a day. I figured the compact version of the date in my PR would be easier to update.
What are you seeing when you say "date input does not seem to do what it should"? I also check the calendar date picker and it seemed to work as I'd expect
As a side note, I've been Vikunja daily for the past 9 months and have been loving it. Thanks for making this available!
I'm seeing the same on
main
as in your branch.Very good question 🙃 might be related to this: https://community.vikunja.io/t/filter-setting-s/1791/3?u=kolaente