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

Same-name Shorthand with imported const #11745

Closed
plehnen opened this issue Aug 29, 2024 · 9 comments
Closed

Same-name Shorthand with imported const #11745

plehnen opened this issue Aug 29, 2024 · 9 comments
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. has workaround A workaround has been found to avoid the problem 🐞 bug Something isn't working scope: sfc

Comments

@plehnen
Copy link

plehnen commented Aug 29, 2024

Vue version

3.4.38

Link to minimal reproduction

https://play.vuejs.org/[...]

Steps to reproduce

There is something really weird happening.
First of all, in the reproduction link I am doing the same as locally, but there the issue is not visible. :(
I import a const (i.e. a string array) and directly pass it to a child component via the same-name shorthand.
In the child the data is not received. It is not in $attrs either. Everything else is passed. But not the imported data.

If I re-assign it to a different variable name, it works:

<script setup lang="ts">
import { linkCollection } from '@/components/overview/myTest'

const linkCollection2 = linkCollection
</script>

<template>
<Comp :link-collection :link-collection2 something="bla" />
</template>

Inside of Comp:

<script setup lang="ts">
const props = defineProps<{
  linkCollection: any
  linkCollection2: any
}>()

defineOptions({
  inheritAttrs: false,
})

console.log('Received data', props)
</script>

Inside Comp I get the following: { "linkCollection2": [ "foo", "bar" ] }.
Isn't that bizare? I mean, I assigned linkCollection2 from linkCollection and passed BOTH to the Comp, but only the latter gets received.
If I change the same-name shortcut :link-collection to :link-collection="linkCollection", it works as expected. Do I change it back it STILL WORKS - until I restart vite (5.4.2).
Seriously, I don't get it.

Super scary. As the linter and vue-tsc don't complain, but the data is just not there.

What is expected?

Imported data should be passed in same-name shortcut as well.

What is actually happening?

Data is undefined.

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (32) x64 Intel(R) Core(TM) i9-14900HX
    Memory: 37.14 GB / 63.71 GB
  Binaries:
    Node: 22.5.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.5.0 - ~\AppData\Local\pnpm\pnpm.EXE
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527

Any additional comments?

No response

@jh-leong
Copy link
Member

It seems the reproduction link is incorrect. Could you please check it?

@plehnen
Copy link
Author

plehnen commented Aug 29, 2024

@jh-leong fixed. Sorry for that. But as I said: it wasn't really possible to re-create it there. Even locally I sometimes need to restart vitest to see the bug.

@LinusBorg
Copy link
Member

We will have a hard time investigating this without a way to reproduce it.

@edison1105 edison1105 added need more info Further information is requested can't reproduce labels Aug 30, 2024
@sunil-sharma-999
Copy link
Contributor

Reproduction Link

Works properly when I switch to Prod

@jh-leong jh-leong added scope: sfc 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. 🐞 bug Something isn't working and removed need more info Further information is requested can't reproduce labels Aug 30, 2024
@edison1105 edison1105 added the has workaround A workaround has been found to avoid the problem label Aug 30, 2024
@edison1105
Copy link
Member

duplicate of #11273

@edison1105 edison1105 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 30, 2024
@LinusBorg
Copy link
Member

@edison1105 This issue here is not related to SSR. If this is a duplicate, does that mean that #11273 is also not related to SSR?

@edison1105
Copy link
Member

@edison1105 This issue here is not related to SSR. If this is a duplicate, does that mean that #11273 is also not related to SSR?

Neither of them is related to SSR.
The underlying problem is the same. The imported bindings are not returned from setup.
image

@plehnen
Copy link
Author

plehnen commented Aug 30, 2024

@edison1105 I just want to point out that it works perfectly fine without the same name shorthand syntax. As soon as I write :link-collection="linkCollection" it gets exported:
image

EDIT: And only if the property is written in "camelCase" and in "kebab-case" in the template. If it is just a single word, it seems to works fine.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. has workaround A workaround has been found to avoid the problem 🐞 bug Something isn't working scope: sfc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants