dom-expressions icon indicating copy to clipboard operation
dom-expressions copied to clipboard

Correctly escape style attribute in SSR output

Open danieltroger opened this issue 1 year ago • 6 comments

Fixes the behavior that you can observe here: https://stackblitz.com/edit/solid-ssr-vite-juconn?file=src%2Fpages%2FHome.tsx where if you put a string that contains a double quote into the style attribute of an element, the server side rendered version isn't correctly escaped. Example: <main data-hk="0.0.0.2.13.0.0.6.0.0.0.0.0.1"><h2 style="--my-var: url("./test.svg");">Home!</h2></main>

Edit: fix wasn't as easy as I thought, gotta improve this a lil

danieltroger avatar Dec 26 '23 12:12 danieltroger

@ryansolid I just noticed this happens with every attribute set in the style of

attribute={`something "with double quotes"`}

Is this enough of a bug report for you? Would appreciate if you could take over this since the issue seems so widespread and I'm unsure how to solve it without further investigation since it seems like it's actually a babel transform issue?

Screenshot 2023-12-26 at 13 53 30

danieltroger avatar Dec 26 '23 12:12 danieltroger

The dots on the hydration key indicates an outdated version.

But I guess it's true that quotes doesn't seem to get escaped.

lxsmnsyc avatar Dec 26 '23 14:12 lxsmnsyc

Yeah I had the issues in solid 1.8.7, the reproduction was just something I pulled out of google to not have to set up an env

danieltroger avatar Dec 26 '23 14:12 danieltroger

Fix should be somewhere here: https://github.com/ryansolid/dom-expressions/blob/b1c5b9d7d9c406070c30d0772eaf9b0e8266f033/packages/babel-plugin-jsx-dom-expressions/src/ssr/element.js#L128

~~escapeHTML could possibly replaced with escapeExpression however I'm not sure yet how this stuff goes~~

Never mind I just realized it's the same function lol

lxsmnsyc avatar Dec 26 '23 14:12 lxsmnsyc

I'm fine merging this one, and then we could just check on the remaining issue with attributes

lxsmnsyc avatar Dec 26 '23 14:12 lxsmnsyc

Sure, sounds good. I'm running this change with yarn patch rn and it fixes the issue with the style attribute for me

But please make sure it gets fixed for the other attributes still :)

danieltroger avatar Dec 26 '23 14:12 danieltroger

Just remembered this - did you make sure to fix the escaping of the attributes for other attributes too or should I open an issue to make sure you don't forget it?

danieltroger avatar Jan 16 '24 15:01 danieltroger