preact-habitat
preact-habitat copied to clipboard
Widget double rendering
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?
@zouhir Seems legit for widget. Any solutions for this?
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