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

Bug with slot props variables #2586

Closed
wsjscss opened this issue Apr 27, 2019 · 6 comments
Closed

Bug with slot props variables #2586

wsjscss opened this issue Apr 27, 2019 · 6 comments
Labels

Comments

@wsjscss
Copy link

wsjscss commented Apr 27, 2019

Repl

https://svelte.dev/repl?version=3.1.0&gist=0597c56d480e14ebe6b5aa7017dd7051

Problem

I try to expose value from <slot>, but get undefined

Solving methods

  1. Create variable with export
// Cnt.svelte
<script>
    export let worldText = "world";
</script>
  1. Create empty variable and store data later
// Cnt.svelte
<script>
    let worldText;
    worldText = "world"
</script>

Why I can't declare variable like usually?

let worldText = "world" 
@just214
Copy link

just214 commented Apr 27, 2019

I might be wrong here, but I believe this is intentional to maintain a one-way data flow and the slot is only able to expose data that was passed down as props from the parent. Similar to the concept of scoped slots in Vue or render props in React.

@just214
Copy link

just214 commented Apr 30, 2019

I was playing around with this again today and see what you mean. I am not sure the reason why you can't create a variable and define it's value in a one-liner. Perhaps it has something to do with the reactivity, but your guess is as good as mine. Hopefully someone will chime in soon and shed some light.

@TehShrike
Copy link
Member

Well that's weird. I'm not sure why it breaks in that example but not in https://svelte.dev/examples#slot-props

@TehShrike TehShrike assigned TehShrike and unassigned TehShrike Jun 1, 2019
@TehShrike TehShrike added the bug label Jun 1, 2019
@LostKobrakai
Copy link
Contributor

The difference seems to be that scalar values don't work, but object (and maybe array, can't remember exactly) do.

@ktquez
Copy link

ktquez commented Jun 2, 2019

It's True, objects and arrays work

Rich-Harris added a commit that referenced this issue Jun 27, 2019
Rich-Harris added a commit that referenced this issue Jun 27, 2019
Rich-Harris added a commit that referenced this issue Jun 29, 2019
* Fixed bug with slot props variables

* dont add hoisted items to context

* alternative fix for #2586

* update slots more conservatively
@Rich-Harris
Copy link
Member

Fixed at last in 3.6.2, thank you! https://svelte.dev/repl/0597c56d480e14ebe6b5aa7017dd7051?version=3.6.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants