Context API doesn't work for custom elements
romangutkin opened this issue · 4 comments
When compiling to custom elements, getContext returns undefined
// Select.svelte
import { setContext } from 'svelte'
setContext('select', {
selected: 'one'
})
// SelectOption.svelte
import { getContext } from 'svelte'
const { selected } = getContext('select') // undefined
it maybe work now.
https://svelte.dev/repl/56b1169a2e2541538225680abd34d2b4?version=3.9.1
A sample repl (I think it needs to be downloaded in order to see the custom element result) https://svelte.dev/repl/138e4c0eb0f340d19e7952064bb9fd19?version=3.20.1
Closed via #8457, to be released in Svelte 4
If anyone is having trouble still getting context to work with custom elements, give svelte-retag
a gander. 👀
Here's a REPL demonstrating a simple version of context with custom elements: https://svelte.dev/repl/b404a1addaf348eabcff3f6089707297?version=4.2.1
You can see a slightly more advanced demo (tabs with nesting) here: https://svelte-retag.vercel.app/.