Preact: Uncaught error when doing dangerouslySetInnerHTML="<svg>...</svg>"

Created on 17 Jun 2016  路  11Comments  路  Source: preactjs/preact

When my dangerouslySetInnerHTML string includes an inline SVG, it renders fine the first time, but when it re-renders I get uncaught errors:

preact.js:158 Uncaught TypeError: Cannot assign to read only property 'height' of object '#<SVGSVGElement>'

I'm guessing this is to do with the fact that inline SVGs require a special module, preact-svg..? But I'm not sure how that can work for my use case, because my SVG is entirely inside the string I am trying to 'dangerously inject'.

Any idea how I can fix this?

bug feedback needed has fix

Most helpful comment

@callumlocke Sorry for the wait there (painting a bedroom) - I just published [email protected] that will allow you to use preact@beta. Let me know if that works!

All 11 comments

@callumlocke what version of Preact are you seeing this with? There should be no Dom property reads anymore in 5.x (npm install --save preact@beta)

I'm using 4. Will give 5.beta a try, thanks. Are there any gotchas for me to be aware of when upgrading to 5?

do I also need to upgrade preact-compat?

Nope, should just be a ton faster and a little smaller :)

There are no backwards-incompatible _changes_ in Preact 5, only a bunch of _additional_ features - the major version bump is just to mark those new features, so that code depending on them has a way to indicate that it won't work with Preact 4.x & prior.

As long as you're running a reasonably recent preact-compat (1.7.1 is the latest, released in April), there's no need to update preact-compat. Expect a minor version bump for that lib before Preact 5.0 gets rolled over to being the current mainline version, though (nothing breaking, just Preact now supports cloneElement() natively, so preact-compat doesn't have to patch that in anymore).

With npm 2, I get a fatal EPEERINVALID when trying to install preact@beta, because preact-compat peer-depends on preact@4. Is there a workaround for that (assuming I can't upgrade to npm3)?

Ah - I've been using npm 3 for so long I forgot about that. I'll throw a preact-compat release out there that allows 5+.

If you could do that soon, that would be awesome!

Will do, I actually found an svg issue when combining preact 5 with preact-compat that I was fixing last night. It's waiting on a decision about whether to bundle svg support into preact itself. I can just publish the -compat version thing though, will do that right away.

@callumlocke Sorry for the wait there (painting a bedroom) - I just published [email protected] that will allow you to use preact@beta. Let me know if that works!

damn, it seems like [email protected]'s peer-dep semver range (*) doesn't actually include the beta! Not sure why. I've asked the question at https://github.com/npm/node-semver/issues/162

Weird... maybe it was because I unpublished and republished? Should be at 5.0.1-beta.14.

I think I can confirm this seems to be fixed in 5.x:
https://jsfiddle.net/developit/j31tf2jd/

Also a note: I just published [email protected], which removes the optionalDependencies field from package.json, which I think might have been causing the semver issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matuscongrady picture matuscongrady  路  3Comments

k15a picture k15a  路  3Comments

jasongerbes picture jasongerbes  路  3Comments

philipwalton picture philipwalton  路  3Comments

rajaraodv picture rajaraodv  路  3Comments