You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I tried to render an interactive svg with the following code
the issue : it loops (n loaded on console, blinking on screen).
Thank you.
I can write a code pen if needed.
constdispatch=(id,detail)=>()=>document.dispatchEvent(newCustomEvent(id,{detail:detail}))constsvg_test=(id,path)=>html`<objecttype="image/svg+xml".data=${path}onload=${dispatch(id)}</object>`;constm={id:'_svg_',path:'a valid path'}constupdate=()=>{render(document.body,svg_test(m.id,m.path));}document.addEventListener(m.id,()=>{console.log("loaded");// do some work here like changing the svgs height/scaleupdate();});update();
OK, this is an expected behavior, see the following code that uses zero libraries:
document.body.innerHTML=`<object height="100px" type="image/svg+xml"></object>`;constobject=document.body.firstElementChild;constm={id: '_svg_',path: 'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/ruby.svg'};constupdate=()=>{object.onload=()=>{document.dispatchEvent(newCustomEvent(m.id,{detail: null}));};object.data=m.path;};document.addEventListener(m.id,()=>{setTimeout(()=>{console.log("loaded");// do some work here like changing the svgs height/scaleupdate();},1000);});update();
setting the .data over and over makes it flick, but admittedly there was no way to pass data as attribute, but nodes that have a special data meaning should have the ability to use that indeed.
So, latest version of uhtml allows you to use data=${...} instead of .data=${...} for nodes where data has a special meaning, so that the dataset helper is not triggered.
Activity
WebReflection commentedon Jun 13, 2020
your
svg_testis broken ... it doesn't close the initial object.would this work instead?
thipages commentedon Jun 13, 2020
Sorry, bad copy/paste.
same behaviour with the code you propose.
I write a code pen
thipages commentedon Jun 13, 2020
here it is : https://codepen.io/thipages/pen/XWXKgBw
WebReflection commentedon Jun 14, 2020
OK, this is an expected behavior, see the following code that uses zero libraries:
setting the
.dataover and over makes it flick, but admittedly there was no way to passdataas attribute, but nodes that have a special data meaning should have the ability to use that indeed.So, latest version of uhtml allows you to use
data=${...}instead of.data=${...}for nodes wheredatahas a special meaning, so that thedatasethelper is not triggered.TL;DR this now works:
Same fix for WebReflection/uhtml#14
thipages commentedon Jun 14, 2020
great! Thank you