-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
refactor(nuxt): use attrs from useAttrs instead of vnode for <NuxtTime />
#33486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
|
WalkthroughThe nuxt-time.vue component was refactored to use Vue's useAttrs() (import added) to read attributes. Locale is now read from attrs['data-locale'] and datetime is sourced from props.datetime for date computation; vnode.el-based extraction of a renderedDate and related hydration logic were removed. The date() helper returns new Date(props.datetime) when datetime is provided, otherwise the current date. No public API or exported declarations were changed. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1)**/*.vue📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
🧠 Learnings (1)📚 Learning: 2025-07-18T16:46:07.446ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
this does indeed look better |
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/nuxt/src/app/components/nuxt-time.vue (1)
2-2: Remove unused import.
getCurrentInstanceis imported but no longer used after replacing vnode access withuseAttrs.-import { computed, getCurrentInstance, onBeforeUnmount, ref, useAttrs } from 'vue' +import { computed, onBeforeUnmount, ref, useAttrs } from 'vue'
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/nuxt/src/app/components/nuxt-time.vue(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.vue
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use
<script setup lang="ts">and the composition API when creating Vue components
Files:
packages/nuxt/src/app/components/nuxt-time.vue
🧠 Learnings (1)
📚 Learning: 2025-07-18T16:46:07.446Z
Learnt from: CR
PR: nuxt/nuxt#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T16:46:07.446Z
Learning: Applies to **/*.vue : Use `<script setup lang="ts">` and the composition API when creating Vue components
Applied to files:
packages/nuxt/src/app/components/nuxt-time.vue
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build
- GitHub Check: code
CodSpeed Performance ReportMerging #33486 will not alter performanceComparing Summary
|
|
I wonder why tests are always passing locally 🤔 |
| const date = computed(() => { | ||
| const date = props.datetime | ||
| if (renderedDate && nuxtApp.isHydrating) { return new Date(renderedDate) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is to avoid hydration mismatch, so we have to somehow get the value of datetime on the current element during hydration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. But this is only the case because we use the vnode.el attributes. As datetime is a prop, it should be the same as the attribute, but it is not because vnode.el.getAttribute("datetime") is actually a bit different.
I assumed that vnode.el.getAttribute('datetime') is the same as the prop, so in this case props.datetime would be equal to renderedDate and this check would not be necessary. But apparently it is not. 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vnode.el attributes are actually the attributes from the SSR response of the actual <time /> element.
|
I dont think
There is also no benefit for #32859 because |
|
@danielroe I think we should just use data-allow-mismatch for nuxt time. FWIW: correcting the mismatches manually should result in the same performance penalty as vues own correction (I think). |
|
happy to explore anything here! whatever we choose, we need to pass data from server -> client in the initial HTML, so it's not just about avoiding a mismatch |
Is this the case? Would it work if we somehow skip the client-side correction of the mismatch? |
🔗 Linked issue
related #32859
📚 Description
I just stumbled upon this. I am opening it to try and understand the reason for using the vnode approach over the
useAttrs.