Skip to content

[Vapor] Bad optimization for some functions #14560

@GeoffreyParrier

Description

@GeoffreyParrier

Vue version

3.6.0-beta.7

Link to minimal reproduction

https://play.vuejs.org/#eNp9kd1KxDAQhV+l5EphTdUVhaUsqOyFgj+olwGJ7djNmiYhmdZC6bs7adkqsvQuc86XyZlJx66d400NbMWykHvlMGmks34tTJaOAh2pQKiclghUJUlWqGbtpSlsdbZKui55kLjlo3B0nPR9lkbiH3o+i2bp9ARbMAy5NZ+q5LtgDYXrYi/Bcls5pcE/OVTWBMGoZXSiJ7W23/eDhr6GxV7Pt5B/HdB3oY2aYM8eAvgGBJs8lL4EHO3N6yO0dJ7Myha1JnrGfIFgdR0zjthNbQqK/Ycb0t5VtGpUpnwLmxbBhP1QMWgk+4EXjH7odmb037hLfjHcE6anLb434GNPWuCSX/LTkw9Aya9Y/wMxRKVa

Steps to reproduce

  • Create a Vapor component
  • Add 2 div containing Math.random

What is expected?

Each divs containing a different random values

What is actually happening?

Both divs contains the same value

System Info

Any additional comments?

Maybe related to #14561

Inside the generated _renderEffect function Math.random() is called once and stored in one variable (see below), it should create one variable for each functions instead.

This is working properly in <script> and <script setup>

Generated _renderEffect

_renderEffect(() => {
  const _Math_random = Math.random()
  _setText(x0, "random1: " + _toDisplayString(_Math_random))
  _setText(x1, "random2: " + _toDisplayString(_Math_random))
})


As #14561 is closed, adding info here for this error:
An error on first load and reload seems that ctx. is prepended to Math.random and parentheses are not present

Generated _renderEffect

_renderEffect(() => {
  const _Math_random = _ctx.Math_random
  _setText(x0, "random1: " + _toDisplayString(_Math_random))
  _setText(x1, "random2: " + _toDisplayString(_Math_random))
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞 bugSomething isn't workingscope: vaporrelated to vapor mode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions