preact-habitat icon indicating copy to clipboard operation
preact-habitat copied to clipboard

Widget double rendering

Open farzeni opened this issue 7 years ago • 3 comments

Hi, First, thank you for this good lib.

I have a problem embedding a widget created with preact-habitat in one Wordpress site. I'm embedding the widget inline, inside a div.

It happens that 'loaded' function (https://github.com/zouhir/preact-habitat/blob/master/src/index.js#L23) is called twice and the last time is called 'window.currentScript' is null so the function 'getExecutedScript' (https://github.com/zouhir/preact-habitat/blob/master/src/lib.js#L20) returns the last script in the page, which is another one different from injection script and the widget is rendered another time at the bottom of the page.

I tryed to reproduce this bug in a clean environment, but without success. This wp site (like many) is a mess of scripts and I really don't know which is the one causing this problem.

I solved my issue adding a variable in 'render' function to control if widget was already rendered, see:

https://github.com/zouhir/preact-habitat/compare/master...farzeni:master

do you have an idea what can be the cause of the problem? or do you think this solution can be merged?

farzeni avatar Aug 24 '18 23:08 farzeni

@zouhir Seems legit for widget. Any solutions for this?

importerror avatar Sep 06 '18 08:09 importerror

sorry I've missed this! that's strange & interesting @farzeni @importerror ...

I will be investigating closely & hopefully deploy a fix asap.

fwiw, @farzeni - your fork's fix look legit

zouhir avatar Sep 06 '18 15:09 zouhir