WebReflection / linkedom

A triple-linked lists based DOM implementation.
https://webreflection.medium.com/linkedom-a-jsdom-alternative-53dd8f699311
ISC License
1.66k stars 80 forks source link

Support for `Element.namespaceURI` ("SVG support") #189

Closed kyr0 closed 1 year ago

kyr0 commented 1 year ago

Hi :)

one small feature request: In case I'm not missing something, the namespaceURI attribute on Element is not set when const el = document.createElementNS("http://www.w3.org/2000/svg", virtualNode.nodeName) is called?

https://dom.spec.whatwg.org/#ref-for-dom-element-namespaceuri%E2%91%A0

I'm rendering JSX via linkedom and I realized that my unit tests were failing with the SVG elements compared to JSDOM. When creating elements using const el = document.createElementNS(SVG_NAMESPACE, virtualNode.type) the namespaceURI doesn't end up being present in el.namespaceURI. This is a bit unfortunate, because in case of SVG, the elements/attributes, such as xlink:href etc. should all be created/set using the setAttributeNS etc. method invariants, but I can't simply check the parent if the namespace is set to decide if I use the NS invariants, because the parentNode doesn't remember its namespaceURI. I could of course hack something in my code as a remedy, but I'd prefer if it was just behaving a little bit more standard compliant here (if I'm not mistaken) :)

Thanks alot and best!

WebReflection commented 1 year ago

This project is about SSR, not unit tests, so anything non SSR related has zero to low priority but this seems to be a generic valid expectation so I'll try to have a look but I have really little time these days and looking for a new job while being daddy 24/7 so ... PR welcome, otherwise I am afraid it might take a while as nobody is sponsoring this project.

kyr0 commented 1 year ago

I see, yeah.. that's a lot on your side... and I hope that you'll find a great new job very soon. I'll see if I can craft a PR :) Also, my other PR is stale since 2021 xD https://github.com/WebReflection/linkedom/pull/96 but I recently had another idea on that.. maybe, maybe I'll find the time and energy to continue there too.

Btw, in my case I have an isomorph DOM renderer abstraction that is passed a Document to work with. So it's pretty agnostic in what it receives. Can be linkedom, a JSDOM or a native Document -- doesn't matter.

Now the Unit Tests weren't happy in SSR rendering with linkedom serialized HTML result as the namespaced attributes didn't look right (they weren't transformed from JSX xlinkHref to xlink:href) and that was because my code didn't run into the if condition that checks for that el.namespaceURI. Because of the isomorphic nature, I'd love to keep the code exactly the same - as it behaves standards compliant.

I think that will be a pretty easy fix so I'll def. try today :) I think I remember this codebase pretty well :)

WebReflection commented 1 year ago

my other PR is stale since 2021

hooking this project into an abandoned proprietary standard is possibly out of scope ... I have recently proposed myself ESX and that might be more in my interests to make it happen, although ESX doesn't require me to do anything here, so that's a plus 😅

kyr0 commented 1 year ago

hooking this project into an abandoned proprietary standard is possibly out of scope

Fair enough :) Interesting thoughts on ESX!

WebReflection commented 1 year ago

I went ahead and fixed this issue with the most sensible and minimal change, I hope that's OK.