merkle-open / gondel

🚡 Gondel is a tiny library to bootstrap frontend components
https://gondel.js.org
MIT License
36 stars 10 forks source link

Decorator Core Plugin is executed twice if gondel is present in multiple js files #48

Closed janwidmer closed 5 years ago

janwidmer commented 5 years ago

Type of issue

The issue refers to:

Expected behavior

Loading the gondel core library multiple times should still trigger a click event only once per click.

Current behavior

If the gondel core library is loaded multiple times a click event is fired multiple times for a single click.

The reason for this bug is the GondelDecorators plugin which hooks itself multiple times in the start event.

There is already a code which tries to prevent this bug however it uses a local variable which will not prevent the bug if gondel is included in multiple different files: https://github.com/namics/gondel/blob/b00e01157f11b8eb886f6b11d4d8f22d02d00bb3/packages/core/src/GondelDecorators.ts#L23

Steps to reproduce the behavior

  1. Include gondel/core twice
  2. Create a simple button component with a click listener.
  3. Click the button
  4. You will see that the click listener is fired twice

Possible solution:

Use a global window variable instead of a local variable

janbiasi commented 5 years ago

Why should you even include gondel multiple times? Just want to figure out the environment of this issue ..

janwidmer commented 5 years ago

I knew that question will come.. ;-) imagine nitro with some prototype js including a button to trigger an overlay on it's demo page..the button was done as gondel component and included in the proto.js entrypoint..that leads to it containing a second gondel core..

Of course the button could be done as plain js which also works..

janwidmer commented 5 years ago

Fixed by https://github.com/namics/gondel/pull/50