You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An empty <template> block means it should render empty string, which is different from no <template> block.
If @vue/compiler-sfc return null for empty <template>, it's difficult for vue-loader / rollup-plugin-vue to determine if the SFC has <template> block or not.
In fact, the only difference is a runtime warning during development:
An empty <template> block is intended by user, which should not be warned.
No <template> block might be a fault, which should be warned.
Questions / Discussion
As we do not have a full specification for vue SFC, some edge cases are not so specific, and the behavior of vue-loader / rollup-plugin-vue / other implementations can be inconsistent.
Here are some edge cases that might need to be determined:
Case A: SFC has both <template> and script.render:
Another edge case as brought up by @znck: no <template>, no root level render, but the setup function returns a render function. In this case the omission of <template> is intentional.
Version
3.0.2
Reproduction link
https://codesandbox.io/s/autumn-wildflower-cqpew?file=/src/index.ts
Steps to reproduce
What is expected?
Consistent with vue2, get the descriptor of empty block.
What is actually happening?
The descriptor of empty block is
null
.Related issues
Explanation
It seems to be intended as the tests show:
https://github.com/vuejs/vue-next/blob/f4621ff5ee4abe924d985177956af3ddc9bb378f/packages/compiler-sfc/__tests__/parse.spec.ts#L114-L119
However, it may cause some breakings in SFC:
<template>
block means it should render empty string, which is different from no<template>
block.@vue/compiler-sfc
returnnull
for empty<template>
, it's difficult forvue-loader
/rollup-plugin-vue
to determine if the SFC has<template>
block or not.In fact, the only difference is a runtime warning during development:
https://github.com/vuejs/vue-next/blob/288c764e5279ccef63e0ef304d4250f5ad935a46/packages/runtime-core/src/component.ts#L711
IMO:
<template>
block is intended by user, which should not be warned.<template>
block might be a fault, which should be warned.Questions / Discussion
As we do not have a full specification for vue SFC, some edge cases are not so specific, and the behavior of
vue-loader
/rollup-plugin-vue
/ other implementations can be inconsistent.Here are some edge cases that might need to be determined:
Case A: SFC has both
<template>
andscript.render
:Which is expected?
script.render
with<template>
script.render
Case B: SFC has empty
<template>
andscript.render
:Which is expected?
script.render
with empty<template>
script.render
Case C: SFC has empty
<template>
, but does not havescript.render
:Which is expected?
script.render
with empty<template>
script.render
with a NOOP as default renderundefined
(will print a runtime warning)Case D: SFC does not have
<template>
norscript.render
:Which is expected?
script.render
with a NOOP as default renderundefined
(will print a runtime warning)@yyx990803 @sodatea @znck
The text was updated successfully, but these errors were encountered: