MCPcopy
hub / github.com/vuejs/core / ssrRenderDynamicAttr

Function ssrRenderDynamicAttr

packages/server-renderer/src/helpers/ssrRenderAttrs.ts:63–85  ·  view source on GitHub ↗
(
  key: string,
  value: unknown,
  tag?: string,
)

Source from the content-addressed store, hash-verified

61
62// render an attr with dynamic (unknown) key.
63export function ssrRenderDynamicAttr(
64 key: string,
65 value: unknown,
66 tag?: string,
67): string {
68 if (!isRenderableAttrValue(value)) {
69 return ``
70 }
71 const attrKey =
72 tag && (tag.indexOf('-') > 0 || isSVGTag(tag))
73 ? key // preserve raw name on custom elements and svg
74 : propsToAttrMap[key] || key.toLowerCase()
75 if (isBooleanAttr(attrKey)) {
76 return includeBooleanAttr(value) ? ` ${attrKey}` : ``
77 } else if (isSSRSafeAttrName(attrKey)) {
78 return value === '' ? ` ${attrKey}` : ` ${attrKey}="${escapeHtml(value)}"`
79 } else {
80 console.warn(
81 `[@vue/server-renderer] Skipped rendering unsafe attribute name: ${attrKey}`,
82 )
83 return ``
84 }
85}
86
87// Render a v-bind attr with static key. The key is pre-processed at compile
88// time and we only need to check and escape value.

Callers 1

ssrRenderAttrsFunction · 0.85

Calls 6

isRenderableAttrValueFunction · 0.90
includeBooleanAttrFunction · 0.90
isSSRSafeAttrNameFunction · 0.90
escapeHtmlFunction · 0.90
indexOfMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected