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 bindings across compilation units #6530

Closed
hgiesel opened this issue Jul 14, 2021 · 4 comments
Closed

Bug with bindings across compilation units #6530

hgiesel opened this issue Jul 14, 2021 · 4 comments

Comments

@hgiesel
Copy link
Contributor

hgiesel commented Jul 14, 2021

Describe the bug

Following scenario: we provide a base app (App.svelte), and some components for users to use (Component.svelte).

The users are supposed to provide their own add-on components (AddOn.svelte), which can use our components, and then add them to the base app through an interface app.addComponent(myaddon). The add-ons are then inserted using <svelte:element bind:this={myaddon} />

When using those provided components inside the add-on, we can set properties, but we cannot bind to them.

Reproduction

https://github.com/hgiesel/svelte-bug-example

Logs

No response

System Info

System:
    OS: macOS 11.2.3
    CPU: (8) x64 Intel(R) Core(TM) i7-1060NG7 CPU @ 1.20GHz
    Memory: 423.93 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: 91.0.4472.114
    Firefox: 89.0.2
    Safari: 14.0.3
  npmPackages:
    svelte: ^3.38.3 => 3.38.3

Severity

blocking all usage of svelte

@hgiesel
Copy link
Contributor Author

hgiesel commented Jul 15, 2021

I could hack it to work by changing:

var binding_callbacks = [];

from here to be

globalThis.binding_callbacks = globalThis.binding_callbacks || [];

That's obviously not the way to go, but it seems to me, that it's not just a bug, but that Svelte does not support combining multiple compilation outputs together. Is this out of scope for Svelte? I assume that in order for this to work, binding_callbacks, render_callbacks, etc. would have to be able to be passed into Svelte components, and also exported on demand so that it can be referenced by other components.

@hgiesel
Copy link
Contributor Author

hgiesel commented Aug 13, 2021

Could I get a feedback for this issue. It would really help me plan for the future.

@dae
Copy link

dae commented Aug 24, 2021

So, the problem here turned out to be bundling multiple copies of svelte/internal, as each copy retains its own state. We were able to work around the issue by exporting the copy bundled with the base code as a global. We exclude svelte from the add-on bundle, and map the call to require("svelte/internal") at runtime to the base code's copy of svelte/internal.

@Conduitry
Copy link
Member

I'm going to close this. Bundling multiple copies of the internals causes a number of issues.

@Conduitry Conduitry closed this as not planned Won't fix, can't repro, duplicate, stale Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants