memos icon indicating copy to clipboard operation
memos copied to clipboard

New memos all get the same createTime while a date filter is active

Open 0bkoi opened this issue 1 month ago • 1 comments

Check before submitting

  • [x] I searched existing issues and did not find a duplicate

Describe the bug

While a displayTime date filter is active on Home (e.g. after clicking a day in the sidebar calendar), every memo created from the composer gets the same createTime: the moment the filter was applied, not the moment of saving.

What happened: I posted four memos over ~20 minutes with today's date selected. All four were stored with an identical create_time (12:40:05), so their order within the day is lost.

What I expected: The selected date is applied (that part is the intended feature from #5925), but the time of day is the current time at save, as the helper's own doc comment says: "combined with now's wall-clock hh:mm:ss, so a memo composed for a past day still orders naturally within it."

Steps to reproduce

  1. Open Home and click today's date in the sidebar calendar (or open /?filter=displayTime:YYYY-MM-DD). The composer now shows a timestamp, e.g. 2026-10-06 13:17:23.
  2. Save a memo. Wait a minute or so and save another, then another.
  3. All of them have createTime = 13:17:23. The timestamp shown in the composer never advances either.

Reproduced on a fresh neosmemo/memos:stable (0.31.0) container with a headless browser:

memo saved at stored createTime
no filter #1 13:17:07 13:17:07
no filter #2 13:17:22 13:17:22
filter #1 13:17:40 13:17:23
filter #2 13:17:55 13:17:23
filter #3 13:18:10 13:17:23

Memos version

v0.31.0 (neosmemo/memos:stable); the same code is still on main@f7a6186

Additional context

Cause. The default is computed once and memoized:

  • web/src/pages/Home.tsx: useMemo(() => deriveDefaultCreateTimeFromFilters(filters), [filters])
  • web/src/components/CalendarView/CalendarView.tsx: the same pattern with [activeDate], and activeDate defaults to today, so the calendar's day composer is affected too.

The resulting Date is seeded into the editor (useMemoInit), re-synced by the useEffect in MemoEditor/index.tsx, and restored after every save (useMemoSave: "restore calendar-derived values for the next memo"). The same frozen value is therefore sent as createTime on every create. The existing tests cover only the pure helper, not consecutive saves from one composer.

Possible fix (small). At save time, if the timestamp is still the untouched default (same Date reference; edits from TimestampPopover produce a new Date), re-stamp its time of day:

// utils/deriveDefaultCreateTime.ts
export function withTimeOfDay(date: Date, now: Date = new Date()): Date {
  const next = new Date(date);
  next.setHours(now.getHours(), now.getMinutes(), now.getSeconds());
  return next;
}

// hooks/useMemoSave.ts, before memoService.save(...)
const restamp = (time?: Date) =>
  !memoName && defaultCreateTime && time === defaultCreateTime ? withTimeOfDay(time) : time;
const timestamps = { createTime: restamp(state.timestamps.createTime), updateTime: restamp(state.timestamps.updateTime) };

This covers both Home and the calendar day panel, and leaves back-dating and manual edits as they are. The composer's displayed time would still be stale, though.

A design question as well. On Home, the date filter is a browsing action, yet it silently changes where new memos are written; the only hint is a grey timestamp that reads like "now". When the selected day is today, the default adds nothing but this side effect. Now that the calendar view has an explicit "New memo on this day" entry (#6280), it may be worth either:

  1. not deriving a default from the Home filter at all, leaving back-dating to the explicit calendar entry; or
  2. at least skipping the default when the selected date is today, and labeling the composer clearly (e.g. "Will be saved to Oct 6") when it is a past day.

I'm happy to send a PR for whichever direction you prefer.

0bkoi avatar Oct 06 '26 05:10 0bkoi

/assign

raghvendrasingh-01 avatar Oct 09 '26 17:10 raghvendrasingh-01