Skip to content

Improve directive SSR #921

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

Merged
merged 4 commits into from
Feb 14, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Support textContent in the directive when using SSR
  • Loading branch information
Demivan committed Feb 14, 2025
commit c4d584cb74642099afac8bd59ddabb98a52b7381
30 changes: 15 additions & 15 deletions src/vue/directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@ export function createVue3Directive(rootContext: TranslationContext): Vue3Direct

getSSRProps(binding) {
const context = getContext(rootContext, binding.instance)
const key = binding.arg
if (key === void 0) {
if (binding.arg === void 0) {
warn('v-t directive is missing arg with translation key')
return {}
}
const translation = context.formatWithAttrs(key, binding.value)
const allowedAttrs = Object.keys(binding.modifiers)
const attrs: Record<string, string> = {}
for (const [attr, attrValue] of Object.entries(translation.attributes)) {
// Vue 3 does not expose the element in the binding object
// so we can't check if the attribute is allowed
// we assume that all attributes are allowed
// this could lead to SSR hydration mismatches if translation
// contains attributes that are not allowed
// There is a runtime warning in the browser console in case translation contains not allowed attributes
if (isAttrNameLocalizable(attr, {} as HTMLElement, allowedAttrs))
attrs[attr] = attrValue

const translation = context.formatWithAttrs(binding.arg, binding.value)

// Vue 3 does not expose the element in the binding object during SSR.
// So we can't check if the attribute is allowed.
// We assume that all attributes are allowed.
// This could lead to SSR hydration mismatches if translation
// contains attributes that are not allowed.
// There is a runtime warning in the browser console in case translation
// contains not allowed attributes, this should catch this case.
const attrs = translation.attributes

if (translation.hasValue) {
attrs.textContent = translation.value
}

// TODO: Include textContent when https://github.com/vuejs/core/issues/8112 is resolved
return attrs
},
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy