DEV Community

Martin Soderlund Ek
Martin Soderlund Ek

Posted on

IOS Render Component Bug in Vue 3

Recently we had a problem where we toggled a CSS class disabled on a component like this:

<my-button :class="{ disabled: !readyToSubmit }" @click="handleSubmit">Submit</my-button>

The CSS class disabled is toggled depending on the computed property readyToSubmit's boolean value.

The problem was, only a few parts of the button changed on IOS/Safari, where all parts of the button changed on all other devices and browsers.

In short, this means the component wasn't properly re-rendered.

How can we best trigger a re-render in Vue? By adding the built in key special attribute to the component and changing its value.

Simply like this:

<my-button :class="{ disabled: !readyToSubmit }" @click="handleSubmit" :key="`MyBtn-${!readyToSubmit}`">Submit</my-button>

To better help Vue to keep track of what has changed and what hasn't, we supply a key attribute.

More on the key attribute in the Vue documentation

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay