If you run confirm
/alert
/prompt
functions and then update the screen after the function returns, the INP and CLS score will be very bad.
For instance, say I create a form to ask my students to enter their name, then I display some content after the input. After the user clicks "OK" to enter his/her name, the CLS and INS penalty score will boost.
$('button').click(()=>{
var name = prompt('enter your name:');
$('#screen1').html(`${name} Hello!<p>
something ...
</p><p>
something ...
</p><p>
something ...
</p><p>
something ...
</p><p>
something ...
</p><p>
something ...
</p><p>
something ...
</p><p>
something ...
</p><p>
something ...
</p><p>
something ...
</p><p>
something ...
</p>`);
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="screen1">
</div>
<button>
Enter Your Name
</button>
I think this is a Web vitals bug. But is there anything I can prevent this for damaging my web vitals score?