`<!----><div></div><div class="parent"></div><!---->`
)
})
+
+ it('should not warn when context.attrs is used during render', () => {
+ const Parent = {
+ render() {
+ return h(Child, { foo: 1, class: 'parent' })
+ }
+ }
+
+ const Child = defineComponent({
+ props: ['foo'],
+ setup(_props, { attrs }) {
+ return () => [h('div'), h('div', attrs)]
+ }
+ })
+
+ const root = document.createElement('div')
+ document.body.appendChild(root)
+ render(h(Parent), root)
+
+ expect(`Extraneous non-props attributes`).not.toHaveBeenWarned()
+ expect(root.innerHTML).toBe(
+ `<!----><div></div><div class="parent"></div><!---->`
+ )
+ })
})
} from '@vue/shared'
import { SuspenseBoundary } from './components/Suspense'
import { CompilerOptions } from '@vue/compiler-core'
-import { currentRenderingInstance } from './componentRenderUtils'
+import {
+ currentRenderingInstance,
+ markAttrsAccessed
+} from './componentRenderUtils'
export type Data = { [key: string]: unknown }
const SetupProxyHandlers: { [key: string]: ProxyHandler<any> } = {}
;['attrs', 'slots'].forEach((type: string) => {
SetupProxyHandlers[type] = {
- get: (instance, key) => instance[type][key],
+ get: (instance, key) => {
+ if (__DEV__) {
+ markAttrsAccessed()
+ }
+ return instance[type][key]
+ },
has: (instance, key) => key === SetupProxySymbol || key in instance[type],
ownKeys: instance => Reflect.ownKeys(instance[type]),
// this is necessary for ownKeys to work properly