Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables defined with let behave differently (v3.2.45) #7417

Closed
kakikubo opened this issue Dec 26, 2022 · 5 comments
Closed

Variables defined with let behave differently (v3.2.45) #7417

kakikubo opened this issue Dec 26, 2022 · 5 comments

Comments

@kakikubo
Copy link

kakikubo commented Dec 26, 2022

Vue version

3.2.45

Link to minimal reproduction

sfc link

Steps to reproduce

Start vue (up to 3.2.44) with yarn dev and access it with a browser using the following sample code.

<script setup lang="ts">
import { ref } from "vue";
const now = new Date();
const nowStr = now.toLocaleTimeString();
let timeStr = nowStr;
const timeStrRef = ref(nowStr);
function changeTime(): void {
  const newTime = new Date();
  const newTimeStr = newTime.toLocaleTimeString();
  timeStr = newTimeStr;
  timeStrRef.value = newTimeStr;
}
setInterval(changeTime, 1000);
</script>

<template>
  <p>timeStr: {{ timeStr }}</p>
  <p>timeStr(ref): {{ timeStrRef }}</p>
</template>

What is expected?

  • timeStr => timeStr is fixed at the time when the screen is opened in the browser
  • timeStr(ref) => timeStr(ref) is updated every second since the screen was opened in the browser

What is actually happening?

When the previous code is executed in vue 3.2.45, the behavior of timeStr and timeStr(ref) is the same.

  • timeStr => timeStr is updated every second since the screen was opened in the browser
  • timeStr(ref) => timeStr(ref) is updated every second since the screen was opened in the browser

System Info

System:
    OS: macOS 12.6.2
    CPU: (10) arm64 Apple M1 Pro
    Memory: 114.20 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.12.1 - ~/.asdf/installs/nodejs/18.12.1/bin/node
    Yarn: 1.22.19 - ~/brew/bin/yarn
    npm: 8.19.2 - ~/.asdf/plugins/nodejs/shims/npm
  Browsers:
    Chrome: 108.0.5359.124
    Safari: 16.2
  npmPackages:
    vue: 3.2.45 => 3.2.45

Any additional comments?

Is there a mistake in the way it is written? If so, I would like to know if you can help me.

note

I can only reproduce this event with Vue SFC PlayGround with the same behavior as 3.2.45. You can actually use the terminal to specify 3.2.44 or 3.2.45 in package.json and run rm yarn.lock && yarn install && yarn dev, etc. to confirm.

@LinusBorg
Copy link
Member

LinusBorg commented Dec 26, 2022

When the component re-renders because you changed the ref, the whole template is updated with all of the latest data. That's how re-renders work. the whole component template virtualDOM is re-rendered with the current data and diffed against the previous version.

@mpg-teruo-kakikubo
Copy link

@LinusBorg
Thank you.
Why is the behavior different from versions up to 3.2.44?

@LinusBorg
Copy link
Member

LinusBorg commented Dec 26, 2022

It isn't - you an see for yourself in the playground, you can switch versions there. If you have a repository to share where this happens, please share it.

@LinusBorg LinusBorg reopened this Dec 26, 2022
@kakikubo
Copy link
Author

@LinusBorg

I have prepared a repository to reproduce this issue. We would appreciate it if you could check it here.
Thank you very much.
https://github.com/kakikubo/vuejs-core-issue-7417

@LinusBorg
Copy link
Member

LinusBorg commented Dec 28, 2022

Ah ses, this was a bug that was fixed in 3.2.45. See:
#5655 (commit f73925d)

@github-actions github-actions bot locked and limited conversation to collaborators Sep 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants