-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Context API (getContext/setContext) does not work across package boundaries with slots #6200
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
Comments
|
@Asv1 Thank you! I had no idea that local packages could be imported with file: protocol; something I probably should have known . When I imported directly from the dist folder do you know why most of the code would work but not the context API? |
@GeoffCox |
Think also that’s not how webcomponents custom elements work they only communicate to the outside with event’s like a input element onchange for example if you want context or similar you would need to make a pubsub event bus and listen to custom dispatched events you could use something like this https://github.com/atomicojs/channel |
Describe the bug
When using the Svelte template and component template a getContext returns undefined for an App-level component that is slotted inside a component from an external component.
This may be a duplicate of: #3422 but that issue is from 2019.
It is possible that I'm including the component package incorrectly in the app. Please let me know if that is the case and what the right way to include a built component is when the component is at a local relative path (and not on NPM).
Logs
Please inspect the console.log output from my example that shows the loading and mounting order of the components and app.
To Reproduce
To help us help you, if you've found a bug please consider the following:
I created a repo with the code here: https://github.com/GeoffCox/svelte-context-issues
It includes a full readme of exactly how I built the app.
I hosted the built code here: https://geoffcox.github.io/svelte-context-issue-demo/index.html
Expected behavior
setContext and getContext work across package boundaries.
Stacktraces
N.A
Stack trace
Stack trace goes here...
Information about your Svelte project:
System:
OS: Windows 10 10.0.19042
CPU: (8) x64 Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
Memory: 23.54 GB / 31.94 GB
Binaries:
Node: 14.16.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.12.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.14.12 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 89.0.4389.128
Edge: Spartan (44.19041.906.0), Chromium (89.0.774.76)
Internet Explorer: 11.0.19041.1
npmPackages:
rollup: ^2.3.4 => 2.45.2
svelte: ^3.0.0 => 3.37.0
Severity
This blocks me from producing a component in Svelte that I want to publish on NPM. I have to be able to pass information to the component that is placed inside a slot from the caller. Without that ability, I would have to go back to a render props approach which would defeat the entire advantage of slots.
Additional context
Unrelated to this bug: I would eventually like to produce a typescript version of the component, but the component template does not have a typescript script like the app template does.
The text was updated successfully, but these errors were encountered: