Skip to content

withDefaults object variable results in non-tree-shakable component #9500

@94726

Description

@94726

Vue version

3.3.4

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-3cmbr7?file=dist%2Fassets%2Findex-311591ca.js

Steps to reproduce

  1. npm run build
  2. open dist/assets/index-....js and scroll to the bottom
  3. see bundled NonTreeshakable

What is expected?

Component should be tree-shaken

What is actually happening?

Component isn't tree-shaken because it compiles to

/* @__PURE__ */ defineComponent({
  __name: "NonTreeshakable",
  props: mergeDefaults({
    prop1: { type: Boolean },
    prop2: {}
  }, propsDefaults),
  setup(__props) {
    ...
  }
});

mergeDefaults ends up being used at the top level and isn't marked as sideEffect-free.

System Info

No response

Any additional comments?

I ran into this after looking into why radix-vue seems way too large compared to how small my imported components are.
Their PopperContent.vue leads to this exact problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔨 p3-minor-bugPriority 3: this fixes a bug, but is an edge case that only affects very specific usage.scope: compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy