glimmerjs / glimmer-vm

MIT License
1.13k stars 190 forks source link

Duplicate @glimmer/validator library blocks rendering #1252

Open john-griffin opened 3 years ago

john-griffin commented 3 years ago

We use Glimmer 2.0.0-beta.12 to generate embed code that runs on third party websites we do not control. Users of our embed code are hitting the assertion The @glimmer/validator library has been included twice in this application. (introduced in #1103) which blocks rendering in a few cases:

These cases worked in older versions of Glimmer. To get around this we are doing the following before loading the Glimmer bundle and inside the Glimmer bundle:

globalThis[Symbol.for('GLIMMER_VALIDATOR_REGISTRATION')] = false;

Would it be possible to relax this restriction or perhaps version the global to allow for multiple Glimmer instances on the same page?

pzuraq commented 3 years ago

It's definitely possible! Other frameworks which have this issue tend have a configuration setting of some type that puts the framework into a no-conflict mode, which allows users to opt into this. We did not add this at the time as we were primarily focused on the majority use case, which are Ember and Glimmer apps that are full SPAs and not embedded on other pages.

I think we could support this via a @glimmer/global-context setting, allowMultipleAutotrackingImplementations or something like that. If set to true, it would skip the above check and assume the user has ensured that they are bundling correctly.

@rwjblue do you think this would be alright?

rwjblue commented 3 years ago

Yes, that seems plausible but I wonder if we should guide folks into actually addressing the issue more fundamentally. Specifically, in this case you really don't want to have to ship the VM multiple times (its a non-trivial waste of bytes at the least). You could bundle the VM code once and share that asset amongst all of your actual apps, and that would avoid the duplicate assertion as well...

knownasilya commented 2 years ago

Seeing this when trying to render a glimmerx component with @glimmerx/ssr.

lifeart commented 2 years ago

@knownasilya fast fix is specify resolutions in package.json to one validator version

knownasilya commented 2 years ago

That didn't help, somehow it still throw the error even if there is only one version because yarn doesn't install only one instance but like 5 with the same version number

knownasilya commented 2 years ago

@rwjblue in my case I'm not doing anything special beyond adding @glimmerx/ssr and other deps like @glimmerx/helper which all depend on this.

wagenet commented 2 years ago

I think this is a false alarm in many cases. I found a situation where it happens if a completely unrelated assertion fires. I'm investigating further now.

acaciabengo commented 2 years ago

Has anyone found a fix for this issue? I am still facing the same. I have tried specifying the same version using overrides.

lifeart commented 2 years ago

Hi @acaciabengo! Try to pin all '@glimmer' packages into single version (if possible) https://github.com/lifeart/glimmerx-workshop/blob/master/package.json#L16

acaciabengo commented 2 years ago

Hi @acaciabengo! Try to pin all '@Glimmer' packages into single version (if possible) https://github.com/lifeart/glimmerx-workshop/blob/master/package.json#L16

In my case found the problem. I was integrating ember js into a rails app using ember-cli-rails. I had already called this; render_ember_app but then also added this; <%= include_ember_script_tags :frontend %> <%= include_ember_stylesheet_tags :frontend %> That is how I ended up with a double call. Otherwise, if you use overrides in the JSON package and make sure all dependencies use the same version, everything work just fine.

danieledraganti commented 1 year ago

Hello, is there any progress on this task? I am working on implementing an Ember web component with the ember-embedded-snipped addon, and I managed to remove all global references, but this warning blocks the possible use of multiple instances.

Thank you in advance!