Skip to content

fix(datetime): preserve year while typing - #8002

Merged
martinjagodic merged 1 commit into
decaporg:release/3.17.2from
Shadorux:7939-fix-datetime-year
Oct 23, 2026
Merged

martinjagodic merged 1 commit into
decaporg:release/3.17.2from
Shadorux:7939-fix-datetime-year

Conversation

@Shadorux

Copy link
Copy Markdown
Contributor

Summary

Fixes #7939.

The datetime widget uses a controlled native date input. While a user edits the year, Chromium can emit intermediate values such as 0002 and 0020. Decap immediately parses those values through Day.js and feeds the formatted parent value back into the input; Day.js normalizes years 0–99 into the 1900s, so 0002-08-03 becomes 1902-08-03 and interrupts the browser's native year-entry buffer.

Keep the native input's exact value while it has focus, while continuing to send changes through the existing onChange path. On blur, the input goes back to rendering the normal formatted prop value. This prevents intermediate parsing from rewriting the active year without changing Decap's persisted value format.

The regression test models the controlled parent rerender and verifies the intermediate 0002 -> 0020 -> 0202 -> 2026 sequence remains intact.

Test plan

  • pnpm exec jest packages/decap-cms-widget-datetime/src/__tests__/DateTimeControl.spec.js --runInBand — 6/6 passed
  • pnpm run test:unit --runInBand — 119 suites / 1,496 tests passed (existing configured skips: 2 suites / 1,304 tests)
  • pnpm exec eslint packages/decap-cms-widget-datetime/src/DateTimeControl.js packages/decap-cms-widget-datetime/src/__tests__/DateTimeControl.spec.js — passed
  • pnpm run lint:js --quiet — passed
  • pnpm run lint:format — passed
  • pnpm run type-check — passed
  • pnpm --filter decap-cms-widget-datetime build:esm — passed
  • pnpm --filter decap-cms-widget-datetime build — passed

Checklist

A picture of a cute animal (not mandatory but encouraged)

🐈

@Shadorux
Shadorux requested a review from a team as a code owner September 23, 2026 20:21
@netlify

netlify Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for decap-cms ready!

Name Link
🔨 Latest commit b56e279
🔍 Latest deploy log https://app.netlify.com/projects/decap-cms/deploys/6ab434b41df4e70008cc559c
😎 Deploy Preview https://deploy-preview-8002--decap-cms.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@yanthomasdev yanthomasdev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@martinjagodic
martinjagodic changed the base branch from main to release/3.17.2 October 23, 2026 12:09
@martinjagodic
martinjagodic merged commit 295904e into decaporg:release/3.17.2 Oct 23, 2026
15 checks passed
@martinjagodic

Copy link
Copy Markdown
Member

Released in v3.17.2

dfdez added a commit to Feverup/decap-cms that referenced this pull request Nov 10, 2026
Backport of upstream 295904e (decaporg#8002, fixes decaporg#7939). The input re-rendered from
the formatted value on every keystroke, so a partial year ("0002") was
rewritten. Keep the typed text while focused; drop it on blur.
dfdez added a commit to Feverup/decap-cms that referenced this pull request Nov 13, 2026
…or fixes (#27)

* fix(backend-github): restore ensurePullRequestLabel

Re-apply the initial workflow label to a CMS pull request that has lost it,
both when listing CMS refs (getCmsRefs) and when opening an unpublished entry
(retrieveUnpublishedEntryData). This behaviour was missing from the source.

PNW-3165

* fix(widgets): keep relation refs intact when list items move (PNW-3165)

Saving a page after removing or inserting a module could write `ref: []`
(or a neighbour's id) into modules below that point.

RelationControl.loadInitialOptions captured onChange before awaiting the
query. That onChange comes from ListControl.handleFieldChangeFor(index),
bound at render time, so the late write landed on the item's OLD index.
On a miss or a failed query (rate limit, cached failure) it wrote fromJS([]).

- RelationControl (upstream decaporg#7497): try/catch around the query; bail on a
  failure or missing hits; call onChange with the original value, and only
  when something matched. Drop the Fever-only componentDidUpdate reload.
- ListControl (upstream decaporg#7972): resolve the item's index from its key when
  the change fires; drop the change if the item is gone. Fall back to the
  creation index if keys and value are out of sync.
- Specs: 4 relation + 3 list cases; 6 fail without the fix.

21 ListControl specs already fail on fork (props lack getWidget); unchanged.

* fix(markdown): remove empty links when text is deleted (decaporg#7702)

When a user deletes all text within a link in the visual markdown
editor, the empty link markup was being left behind (visible when
switching to raw markdown mode).

This adds a Slate normalizer that automatically removes link nodes
when they become empty (have no text content), ensuring the link
markup is properly cleaned up along with the text.

Fixes decaporg#7640

(cherry picked from commit f1f1d13)

* fix: 7431 - code widget Ignore initial lang change to prevent false unsaved changes state (decaporg#7588)

* fix: 7431 - code widget Ignore initial lang change to prevent false unsaved changes state

* 7588: apply copilot nitpick

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Martin Jagodic <jagodicmartin1@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
(cherry picked from commit 7576d1c)

* fix(lib-util): do not retry a 403 whose body has no message

Backport of the requestWithBackoff part of upstream 20c99e0. A 403 without
a string `message` (proxy error, null body) threw a TypeError that the catch
took for a network failure, retrying five times over ~55s.

(cherry picked from commit 20c99e0, lib-util only)

* fix(widget-relation): stop the options menu hanging when a search fails

Backport of upstream 0c191ed (decaporg#7556) and 2f3bdd4. loadOptions had no catch:
a failed query (rate limit, network) never called react-select's callback,
so the menu stayed on "Loading..." until reload. With a search term, put the
matches ahead of the selected options before truncating to options_length.

* fix(widget-datetime): preserve the year while it is being typed

Backport of upstream 295904e (decaporg#8002, fixes decaporg#7939). The input re-rendered from
the formatted value on every keystroke, so a partial year ("0002") was
rewritten. Keep the typed text while focused; drop it on blur.

* fix(core): flag drafts that delete a file as a delete workflow again

A merge renamed the read in processUnpublishedEntry from
dataFile.deletedFile to dataFile.deleteFile, matching a typo in
UnpublishedEntryDiff. Backends return deletedFile, so isDeleteWorkflow was
always null and delete-workflow drafts were treated as normal publishes
(toast and post-publish handling). Rename the type field to deletedFile;
it is optional because only some backends report it.

* chore: make lint:format and type-check pass on the fork

CI stopped at lint:format (API.ts formatting), which also hid 13 type-check
errors. All are type-only:
- Stack methods on Implementation are optional: only the GitHub backend
  implements them, and stack actions only run with backend.stack.
- stackPublishFailure/stackCloseFailure accept the error their callers pass.
- Narrow mediaLibrary state.get('validation') to its declared type.
- prettier on backend-github API.ts (missing semicolon, line wrap).

* fix(widget-markdown): keep links whose only content is an image

Empty-link cleanup used Node.string(), so [![alt](src)](href) normalized
away with its image. Treat a link as empty only with no text and no void child.

* fix(widget-code): save the first language picked on a field with no initial language

With no saved lang and no default_language, mount never changed lang, so
isLangInitialized stayed false and the user's first pick was dropped as the init write.

---------

Co-authored-by: Eric Grill <694055+EricGrill@users.noreply.github.com>
Co-authored-by: Dan Ford <22881850+dlford@users.noreply.github.com>
Co-authored-by: Martin Jagodic <jagodicmartin1@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

datetime widget corrupts year while typing (e.g. "2026" silently becomes "1906")

3 participants