Skip to content

fix(common): warn in dev mode when toDate() receives an unrecognized string format#68909

Open
arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:fix/common_to_date_warn
Open

fix(common): warn in dev mode when toDate() receives an unrecognized string format#68909
arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:fix/common_to_date_warn

Conversation

@arturovt
Copy link
Copy Markdown
Contributor

@arturovt arturovt commented May 24, 2026

toDate() falls back to new Date(value) when the input string does not match
any of Angular's supported date formats. This fallback is kept for backwards
compatibility but is unsafe: non-ISO strings (e.g. 'Jan 15 2024') are parsed
relative to the local timezone, so a server in UTC and a browser in UTC+8 will
compute different Date values from the same string — producing inconsistent
rendered output and potentially incorrect results when the date drives logic such
as access-control or expiry checks.

To surface this before the fallback is eventually removed, emit a console.error
(dev mode only) that identifies the offending value and instructs callers to pass
an ISO 8601 string, a numeric timestamp, or a Date object instead.

@angular-robot angular-robot Bot added the area: common Issues related to APIs in the @angular/common package label May 24, 2026
@ngbot ngbot Bot added this to the Backlog milestone May 24, 2026
@arturovt arturovt marked this pull request as ready for review May 24, 2026 21:33
@pullapprove pullapprove Bot requested a review from JeanMeche May 24, 2026 21:33
@JeanMeche
Copy link
Copy Markdown
Member

JeanMeche commented May 25, 2026

a server running in UTC and a browser in UTC+8 will produce different dates from the same input string, causing SSR hydration mismatches

Does it though ? Our hydration process shouldn't be sensible to text changes.

@arturovt arturovt force-pushed the fix/common_to_date_warn branch from d439124 to 4255665 Compare May 25, 2026 13:35
@arturovt
Copy link
Copy Markdown
Contributor Author

@JeanMeche you're right, i checked text.ts, it only claims DOM nodes by position, no content comparison. I've updated commit description.

…d string format

`toDate()` falls back to `new Date(value)` when the input string does not match
any of Angular's supported date formats. This fallback is kept for backwards
compatibility but is unsafe: non-ISO strings (e.g. `'Jan 15 2024'`) are parsed
relative to the local timezone, so a server in UTC and a browser in UTC+8 will
compute different `Date` values from the same string — producing inconsistent
rendered output and potentially incorrect results when the date drives logic such
as access-control or expiry checks.

To surface this before the fallback is eventually removed, emit a `console.error`
(dev mode only) that identifies the offending value and instructs callers to pass
an ISO 8601 string, a numeric timestamp, or a `Date` object instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: common Issues related to APIs in the @angular/common package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants