Why scrollHeight changes when value is entered in textArea

Firefox: 71.0 (64)

When you click the button, observe the console, the value printed twice is different。
Why is this so?

The source code is below

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    textarea {
      letter-spacing: normal;

      line-height: 1;
      padding-top: 10px;
      padding-bottom: 10px;

      font-family: "Monospaced Number", "Chinese Quote", -apple-system, system-ui, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
      font-weight: 400;
      font-size: 13px;
      text-rendering: optimizeLegibility;
      text-transform: none;
      width: 178px;
      text-indent: 0px;
      padding-left: 10px;
      padding-right: 10px;
      border-width: 1px;
      box-sizing: content-box;
      min-height: 0 !important;
      max-height: none !important;

      height: 13px !important;
      visibility: hidden !important;
      overflow: hidden !important;
      position: absolute !important;
      z-index: -1000 !important;
      top: 0 !important;
      right: 0 !important;
    }
  </style>
</head>

<body>
  <button id="btn">btn</button>
  <script>
    document.getElementById('btn').addEventListener('click', () => {
      hiddenTextarea = document.createElement('textarea');
      document.body.appendChild(hiddenTextarea);
      console.log(hiddenTextarea.scrollHeight)
      hiddenTextarea.value = 'sfdsf'
      console.log(hiddenTextarea.scrollHeight)
    })
  </script>
</body>

</html>

maybe because that line written twice one before hiddenTextarea.value = ‘sfdsf’ then one after it so it the height change cause of the added data :wink:

hope that help and have a nice day :slight_smile: