Skip to content

Context API (getContext/setContext) does not work across package boundaries with slots #6200

@GeoffCox

Description

@GeoffCox

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions