question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues rendering functional components

See original GitHub issue

Given the following test:

import { render } from '@testing-library/vue'

const Functional = {
  functional: true,
  template: `<p>Hi!</p>`,
}

it('renders functional comp', () => {
  const { getByText } = render(Functional)

  getByText('Hi!')
})

Running tests output the following error:

imatge

The error is obviously gone when removing the functional: true attribute.


However, creating a SFC component and setting the functional tag on <template> works:

<template functional>
  <p>Hi!</p>
</template>

Then, tests don’t break.

On the other hand, using SFC then throws when trying to use afterEach(cleanup):

[vue-test-utils]: wrapper.destroy() can only be called on a Vue instance

In this case, setting a wrapper component to render the functional one solves the issue. I was hoping I could fix the other issue the same way, but didn’t work 😕 I’m guessing internal implementation for creating a functional component changes due to SFC.

I could submit a PR to provide a wrapper element if the rendered component is functional, but that won’t solve all problems (probably). Is still worth the effort? Can you think of any other possible solution?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dfcookcommented, Aug 13, 2019

Added support for functional SFC without a component Pure functional components look like they need to supply a render function rather than a template, added an example illustrating this.

0reactions
afontcucommented, Jul 30, 2019

do you mean something like this?

const Comp = Vue.extend({
  template: `<div>hello world</div>`
})

new Comp().$mount('#app')

Can’t think of a simpler way to render a component 🤔

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debug functional component re-rendering issue
Check how many times the functional component is rendering · When to use shallowEqual with useSelector · Avoid using multiple useSelectors ...
Read more >
Re-rendering in React functional component - Stack Overflow
React may re-render some part of your app for various internal reasons. I'm guessing it renders the top level component for one of...
Read more >
5 Ways to Avoid React Component Re-Renderings
React components have evolved a long way from their inception. Still, many developers find it hard to fix unnecessary re-renderings.
Read more >
How and when to force a React component to re-render
React automatically re-renders components, but what happens when a component is not updating as expected? Find out what you can do here.
Read more >
When does React re-render components? - Felix Gerschau
All your code in these render functions or function components will be ... in the world won't help you to fix your performance...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found