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 when passing getAllContexts() to new Component({ context }) #6753

Closed
hgiesel opened this issue Sep 21, 2021 · 3 comments · Fixed by #6759
Closed

Bug when passing getAllContexts() to new Component({ context }) #6753

hgiesel opened this issue Sep 21, 2021 · 3 comments · Fixed by #6759
Labels
bug runtime Changes relating to runtime APIs

Comments

@hgiesel
Copy link
Contributor

hgiesel commented Sep 21, 2021

Describe the bug

Some contexts are unexplicably removed from the map object when passing it to new Component().

From #6447 it seems like this was it's intended usage.

Reproduction

https://svelte.dev/repl/178ba9c6c46a43b9bcd8376262f1d021?version=3.42.6.
(note: In production, I would not render in a normal div, but rather in a shadow DOM)

Logs

No response

System Info

System:
    OS: macOS 11.5.2
    CPU: (8) x64 Intel(R) Core(TM) i7-1060NG7 CPU @ 1.20GHz
    Memory: 213.38 MB / 8.00 GB
    Shell: 5.1.4 - /usr/local/bin/bash
  Binaries:
    Node: 16.0.0 - /usr/local/bin/node
    Yarn: 1.22.5 - ~/.yarn/bin/yarn
    npm: 7.10.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 93.0.4577.82
    Firefox: 92.0
    Safari: 14.1.2
  npmPackages:
    svelte: ^3.25.0 => 3.42.6

Severity

blocking all usage of svelte;
after this comment, it's just an annoyance (and pitfall)

@hgiesel
Copy link
Contributor Author

hgiesel commented Sep 21, 2021

It seems like the context you pass in is completely ignored, which is because of this line:

context: new Map(parent_component ? parent_component.$$.context : options.context || []),

which would need to be changed to give preference to options.context, something like this:

context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),

@Conduitry
Copy link
Member

Preferring options.context makes sense, I think, but I haven't thought through all of the implications of that. For now, to make sure parent_component isn't set, you can just avoid synchronously instantiating a component inside another one. Adding a setTimeout around the new GetContext makes this behave in the way you want.

@Conduitry Conduitry added bug runtime Changes relating to runtime APIs labels Sep 21, 2021
@Conduitry
Copy link
Member

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

Successfully merging a pull request may close this issue.

2 participants