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

switching between multiple embedded components seems buggy #361

Open
sk-t3ch opened this issue Jul 22, 2021 · 23 comments
Open

switching between multiple embedded components seems buggy #361

sk-t3ch opened this issue Jul 22, 2021 · 23 comments
Labels

Comments

@sk-t3ch
Copy link

sk-t3ch commented Jul 22, 2021

Describe the bug
I have a few nuxt-custom-elements components embedded in my website (https://t3chflicks.org/Services) which are loaded from an external source (document-store.t3chflicks.org, medium-to-markdown.t3chflicks.org). When I switch page, loading a diferrent nuxt-custom-elements component, there seems to be odd behaviour:

  • reloading the same component instead of new one
  • failing to load with an error of
    Uncaught TypeError: Illegal constructor
     at new n (viewer-component.js:432)
    

To Reproduce
Steps to reproduce the behavior:

Sorry if this isnt enough informatio, please say if you would like an example project.

Cheers

@ThornWalli
Copy link
Contributor

Hello @sk-t3ch,

The error message comes from the polyfill @ungap/custom-elements. It then comes to a mixing when changing pages and gives an error between the different bundles.

Solution would be to disable the polyfill in the bundles (https://nuxt-custom-elements.grabarzundpartner.dev/options/#polyfill). And if needed, build it directly into your page.

@rmarmitt
Copy link

Hey, maybe this occours because "destroyTimeout" property in vue-custom-element?

I caught this same scenario during testing. Browsing between pages with multiple components, they start to get destroyed.

@ThornWalli
Copy link
Contributor

Close the issue for now, but can be reopened if used.

@rmarmitt
Copy link

rmarmitt commented Jun 14, 2022

Hi there.

Well, after some more tests I can confirm: it's happening even with polyfill disabled, but only in external sources.

oh lord. Today isn't a good day.

I was adding tag in wrong context. I'm sorry

@sk-t3ch
Copy link
Author

sk-t3ch commented Jun 16, 2022

Can i see your working version, I stopped using it because of this problem

@sk-t3ch
Copy link
Author

sk-t3ch commented Jun 16, 2022

@ThornWalli
Copy link
Contributor

Reopen this issue for now 🙂

@ThornWalli ThornWalli reopened this Jun 16, 2022
@rmarmitt
Copy link

rmarmitt commented Jun 16, 2022

Can i see your working version, I stopped using it because of this problem

Hi sk-t3ch, I have added "polyfill: false" to customElements config, and also "destroyTimeout: null" in tags.

But i don't know if destroyTimeout is really required in this case. Needs more tests.

E.g nuxt.config.js

customElements : {
  polyfill: false,
  entries: [
    {
      name: 'exampleEntry',
      tags: [
        {
          name: 'exampleTag',
          options: {
            destroyTimeout: null
          }
        }
      }
    ]
  ]
}

Also, polyfill is highly recommended because of compatibility between browsers, and this should be an temporarily workaround.

@sk-t3ch
Copy link
Author

sk-t3ch commented Jun 17, 2022

thanks @rmarmitt, I will try that.

@ThornWalli you mention

build it directly into your page

Sorry, I am inexperienced. How would this be done? Could you share a link to something similar?

@sk-t3ch sk-t3ch closed this as completed Jun 17, 2022
@sk-t3ch sk-t3ch reopened this Jun 17, 2022
@ThornWalli
Copy link
Contributor

I meant that the polyfill is used on the target side. But it is also not nice...

Yesterday I wanted to look at the problem again, unfortunately I don't get an example built so far.

Question is whether you get even when initializing the polyfill with whether this is already set, so you could then block the import.

<% if (options.polyfill && (options.modernPolyfill || !options.modern)) { %>
import '@ungap/custom-elements'; // For cross-browser compatibility https://github.com/ungap/custom-elements.
<% } %>

@rmarmitt
Copy link

I meant that the polyfill is used on the target side. But it is also not nice...

Yesterday I wanted to look at the problem again, unfortunately I don't get an example built so far.

Question is whether you get even when initializing the polyfill with whether this is already set, so you could then block the import.

Hey @ThornWalli, do you need an reproduction case? I can provide an repo with steps to reproduce the problem.

But basically, create two pages, A and B, add the builded js on the target A and navigate between those pages multiple times (at least 3 times). You will see the bug.

@ThornWalli ThornWalli mentioned this issue Jun 17, 2022
@ThornWalli
Copy link
Contributor

@sk-t3ch @rmarmitt There is an update on the beta branch (nuxt-custom-elements@1.9.1-beta.2).

Can you test this? 🙂

There are two changes:

  1. Chunks were written to existing webpackJsonp from existing webpack instances.
    This is now a separate object for each entry.
    I found this because I have two different entries on page a and b. And one of them would not initialize.

jsonpFunction: getJsonPFunctionName(entryName)

function getJsonPFunctionName (entryName) {
// eslint-disable-next-line no-secrets/no-secrets
return 'webpackJsonpNuxtCustomElements' + pascalCase(entryName);
}

  1. Added a switch for the polyfill.

<% if (options.polyfill && (options.modernPolyfill || !options.modern)) { %>
if (!global.__NUXT_CUSTOM_ELEMENTS_POLYFILL) {
require('@ungap/custom-elements'); // For cross-browser compatibility https://github.com/ungap/custom-elements.
global.__NUXT_CUSTOM_ELEMENTS_POLYFILL = true;
}
<% } %>

@rmarmitt
Copy link

rmarmitt commented Jun 17, 2022

@ThornWalli I cannot find any pacakge with version "1.9.1-beta.2".

If I install nuxt-custom-elements@beta, its getting1.9.0-beta.2

Can you confirm if the build was generated and published?

Also I have tried install targeting the branch https://github.com/GrabarzUndPartner/nuxt-custom-elements.git#v1.9.1-beta.2,
but I get some errors from husky

@ThornWalli
Copy link
Contributor

ThornWalli commented Jun 17, 2022

Mmhhhh https://www.npmjs.com/package/nuxt-custom-elements/v/1.9.1-beta.2

The package must be installed via npm, is conditional on Husky...

image

pinst deactivates the postinstall.

@rmarmitt
Copy link

rmarmitt commented Jun 17, 2022

image

edit: even with npm cache clean I got this error.

@ThornWalli
Copy link
Contributor

ThornWalli commented Jun 17, 2022

@rmarmitt

I can install it.
image

This is rather strange now, even with unpkg I get it displayed.
https://unpkg.com/browse/nuxt-custom-elements@1.9.1-beta.2/

What do you get with $ npm show nuxt-custom-elements versions?

@rmarmitt
Copy link

well this really is quite strange

image

Looks like a cache problem?! Idk

@ThornWalli
Copy link
Contributor

image

That's what I'm thinking too, tried the npm cache clean --force?

@rmarmitt
Copy link

Lol. Even with --force, no success.

With yarn works. Let's change and make some tests.

asap I will return with an feedback.

Thank you very much :)

@rmarmitt
Copy link

@ThornWalli looks like the polyfill problem its solved 🚀

Just remember to keep "destroyTimeout: null" in tags, otherside the components will be destroyed after timeout.

Idk why, but if you don't remove this property you will have problems with rendering.

This is what the vue-custom-element documentation says:

/* 
in case of using vue-custom-element with modals, we destroy  
it after defined timeout. Use "null" value if you want to manually "$destroy" it.
*/
destroyTimeout: 3000

@ThornWalli
Copy link
Contributor

@rmarmitt could you maybe build a small example that needs the destroyTimeout modification?

Haven't had this problem yet and in my example with two different entries on two pages I have no problems.

@ThornWalli
Copy link
Contributor

Fix is now in the main branch. https://www.npmjs.com/package/nuxt-custom-elements/v/1.9.1

@rmarmitt
Copy link

@rmarmitt could you maybe build a small example that needs the destroyTimeout modification?

Haven't had this problem yet and in my example with two different entries on two pages I have no problems.

Sure, I'll do it this weekend and let you know.

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

No branches or pull requests

3 participants