@@ -288,55 +288,78 @@ describe('ssr: element', () => {
288
288
}></div>\`"
289
289
` )
290
290
} )
291
+ } )
291
292
292
- test ( 'custom dir' , ( ) => {
293
+ describe ( 'custom directives' , ( ) => {
294
+ // #8112 should respect textContent / innerHTML from directive getSSRProps
295
+ // if the element has no children
296
+ test ( 'custom dir without children' , ( ) => {
293
297
expect ( getCompiledString ( `<div v-xxx:x.y="z" />` ) ) . toMatchInlineSnapshot ( `
298
+ "\`<div\${
299
+ _ssrRenderAttrs(_temp0 = _ssrGetDirectiveProps(_ctx, _directive_xxx, _ctx.z, "x", { y: true }))
300
+ }>\${
301
+ ("textContent" in _temp0) ? _ssrInterpolate(_temp0.textContent) : _temp0.innerHTML ?? ''
302
+ }</div>\`"
303
+ ` )
304
+ } )
305
+
306
+ test ( 'custom dir with children' , ( ) => {
307
+ expect ( getCompiledString ( `<div v-xxx:x.y="z">hello</div>` ) )
308
+ . toMatchInlineSnapshot ( `
294
309
"\`<div\${
295
310
_ssrRenderAttrs(_ssrGetDirectiveProps(_ctx, _directive_xxx, _ctx.z, "x", { y: true }))
296
- }></div>\`"
311
+ }>hello </div>\`"
297
312
` )
298
313
} )
299
314
300
315
test ( 'custom dir with normal attrs' , ( ) => {
301
316
expect ( getCompiledString ( `<div class="foo" v-xxx />` ) )
302
317
. toMatchInlineSnapshot ( `
303
318
"\`<div\${
304
- _ssrRenderAttrs(_mergeProps({ class: "foo" }, _ssrGetDirectiveProps(_ctx, _directive_xxx)))
305
- }></div>\`"
319
+ _ssrRenderAttrs(_temp0 = _mergeProps({ class: "foo" }, _ssrGetDirectiveProps(_ctx, _directive_xxx)))
320
+ }>\${
321
+ ("textContent" in _temp0) ? _ssrInterpolate(_temp0.textContent) : _temp0.innerHTML ?? ''
322
+ }</div>\`"
306
323
` )
307
324
} )
308
325
309
326
test ( 'custom dir with v-bind' , ( ) => {
310
327
expect ( getCompiledString ( `<div :title="foo" :class="bar" v-xxx />` ) )
311
328
. toMatchInlineSnapshot ( `
312
- "\`<div\${
313
- _ssrRenderAttrs(_mergeProps({
314
- title: _ctx.foo,
315
- class: _ctx.bar
316
- }, _ssrGetDirectiveProps(_ctx, _directive_xxx)))
317
- }></div>\`"
318
- ` )
329
+ "\`<div\${
330
+ _ssrRenderAttrs(_temp0 = _mergeProps({
331
+ title: _ctx.foo,
332
+ class: _ctx.bar
333
+ }, _ssrGetDirectiveProps(_ctx, _directive_xxx)))
334
+ }>\${
335
+ ("textContent" in _temp0) ? _ssrInterpolate(_temp0.textContent) : _temp0.innerHTML ?? ''
336
+ }</div>\`"
337
+ ` )
319
338
} )
320
339
321
340
test ( 'custom dir with object v-bind' , ( ) => {
322
341
expect ( getCompiledString ( `<div v-bind="x" v-xxx />` ) )
323
342
. toMatchInlineSnapshot ( `
324
- "\`<div\${
325
- _ssrRenderAttrs(_mergeProps(_ctx.x, _ssrGetDirectiveProps(_ctx, _directive_xxx)))
326
- }></div>\`"
327
- ` )
343
+ "\`<div\${
344
+ _ssrRenderAttrs(_temp0 = _mergeProps(_ctx.x, _ssrGetDirectiveProps(_ctx, _directive_xxx)))
345
+ }>\${
346
+ ("textContent" in _temp0) ? _ssrInterpolate(_temp0.textContent) : _temp0.innerHTML ?? ''
347
+ }</div>\`"
348
+ ` )
328
349
} )
329
350
330
351
test ( 'custom dir with object v-bind + normal bindings' , ( ) => {
331
352
expect (
332
353
getCompiledString ( `<div v-bind="x" class="foo" v-xxx title="bar" />` ) ,
333
354
) . toMatchInlineSnapshot ( `
334
355
"\`<div\${
335
- _ssrRenderAttrs(_mergeProps(_ctx.x, {
356
+ _ssrRenderAttrs(_temp0 = _mergeProps(_ctx.x, {
336
357
class: "foo",
337
358
title: "bar"
338
359
}, _ssrGetDirectiveProps(_ctx, _directive_xxx)))
339
- }></div>\`"
360
+ }>\${
361
+ ("textContent" in _temp0) ? _ssrInterpolate(_temp0.textContent) : _temp0.innerHTML ?? ''
362
+ }</div>\`"
340
363
` )
341
364
} )
342
365
} )
0 commit comments