Skip to content

fix: fork <NuxtTime> for i18n support#699

Closed
danielroe wants to merge 4 commits intomainfrom
fix/datetime
Closed

fix: fork <NuxtTime> for i18n support#699
danielroe wants to merge 4 commits intomainfrom
fix/datetime

Conversation

@danielroe
Copy link
Copy Markdown
Member

@danielroe danielroe commented Feb 2, 2026

this addresses some hydration mismatches we were encountering, and prevents layout shift/flicker

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs.npmx.dev Ready Ready Preview, Comment Feb 8, 2026 0:05am
npmx.dev Ready Ready Preview, Comment Feb 8, 2026 0:05am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
npmx-lunaria Ignored Ignored Feb 8, 2026 0:05am

Request Review

day: undefined,
},
)
interface NuxtTimeProps {
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.

Could these be simply imported from nuxt/dist/app/components/nuxt-time.d.vue.ts?

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 7, 2026

Codecov Report

❌ Patch coverage is 60.41667% with 19 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
app/components/DateTime.vue 60.41% 15 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

Comment on lines +53 to 63
const formatter = computed(() => {
const { relativeStyle, ...rest } = props
if (relativeDates.value) {
return new Intl.RelativeTimeFormat(_locale ?? locale.value, {
...defaults,
...rest,
style: relativeStyle,
})
}
return new Intl.DateTimeFormat(_locale ?? locale.value, { ...defaults, ...rest })
})
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.

Maybe we could avoid type assertions by doing:

Suggested change
const formatter = computed(() => {
const { relativeStyle, ...rest } = props
if (relativeDates.value) {
return new Intl.RelativeTimeFormat(_locale ?? locale.value, {
...defaults,
...rest,
style: relativeStyle,
})
}
return new Intl.DateTimeFormat(_locale ?? locale.value, { ...defaults, ...rest })
})
const relativeFormatter = computed(() => {
const { relativeStyle, ...rest } = props
return new Intl.RelativeTimeFormat(_locale ?? locale.value, {
...defaults,
...rest,
style: relativeStyle,
})
})
const formatter = computed(() => {
const { relativeStyle, ...rest } = props
return new Intl.DateTimeFormat(_locale ?? locale.value, { ...defaults, ...rest })
})

?

// eslint-disable-next-line eslint-plugin-unicorn/consistent-function-scoping
const toCamelCase = (name: string, index: number) => {
if (index > 0) {
return name[0]!.toUpperCase() + name.slice(1)
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.

Suggested change
return name[0]!.toUpperCase() + name.slice(1)
return name.charAt(0).toUpperCase() + name.slice(1)

will avoid the need of non-null assertion

Comment on lines +123 to +131
let optionName = name
.slice(5)
.split('-')
.map(toCamelCase)
.join('') as keyof (Intl.DateTimeFormatOptions & Intl.RelativeTimeFormatOptions)

if ((optionName as string) === 'relativeStyle') {
optionName = 'style'
}
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.

Maybe just a tiny bit more accurate - still assertion needed but at least we're "telling the truth" here:

Suggested change
let optionName = name
.slice(5)
.split('-')
.map(toCamelCase)
.join('') as keyof (Intl.DateTimeFormatOptions & Intl.RelativeTimeFormatOptions)
if ((optionName as string) === 'relativeStyle') {
optionName = 'style'
}
let optionName = name.slice(5).split('-').map(toCamelCase).join('') as
| keyof (Intl.DateTimeFormatOptions & Intl.RelativeTimeFormatOptions)
| 'relativeStyle'
if (optionName === 'relativeStyle') {
optionName = 'style'
}

Copy link
Copy Markdown
Contributor

@ghostdevv ghostdevv left a comment

Choose a reason for hiding this comment

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

Is this still necessary?

@serhalp
Copy link
Copy Markdown
Member

serhalp commented Apr 6, 2026

@danielroe I'll close it for now, feel free to reopen if I'm wrong :)

@serhalp serhalp closed this Apr 6, 2026
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.

4 participants