riot / ssr

Riot.js node Server Side Rendering
MIT License
32 stars 8 forks source link

Best DOM library #29

Closed Kal-Aster closed 2 years ago

Kal-Aster commented 3 years ago

Hi, recently riot/ssr switch from basicHTML to the suggested by them linkedom. linkedom seems pretty good, mainly for its speed, but I'm encountering a lot of problems with it (#73, #88, #92) because it's not their aim to be 1:1 with Web specs...

Since riot/ssr should have the same behavior of a browser, wouldn't it be better to switch to another library that aims to this, I'd say, requirement? linkedom often suggests JSDOM

What do you think?

WebReflection commented 3 years ago

I'm encountering a lot of problems

how so? basicHTML didn't have StyleSheetDeclaration neither, the event MR is under review, and your MR never landed, you just opened an issue.

Anyway, if you need a 100% specs compliant NodeJS module, there's JSDOM for that. Just be aware it fails with the very same W3C page, it's 2x up to 10x slower, and so on ... the linkedom use case is to do SSR, not to test 1:1 what a browser does, so if that's your requirement, yes, I strongly suggest you use JSDOM.

WebReflection commented 3 years ago

P.S. I am surprised the LinkeDOM use case came as surprise though ... maybe reading its introduction post (linked in the repo) would help: https://webreflection.medium.com/linkedom-a-jsdom-alternative-53dd8f699311

If you look for a never crashing fast and close enough to standards solution, LinkeDOM is better than JSDOM. If you look for a project which goal is not perf but being close to specs, with all caveats I've mentioned and that you can test via LinkeDOM benchmarks too, then JSDOM is better. It's a matter of trade offs.

Kal-Aster commented 3 years ago

I actually like linkedom, and basicHTML had problems too and that's why I PR here to switch to linkedom. I read that post and that's a reason why I like it: it uses a quite clever strategy.

I didn't want to offend you, if you feel so. I even enjoyed contributing and I'll surely keep doing it. I'm just trying to understand what is better for riot/ssr.

GianlucaGuarini commented 3 years ago

@Kal-Aster I think we could offer a way to plug in your own create/cleanDOM drivers. We can use linkedom as standard library but you will be able to plug in JSDOM or whatever you want by options.

For example

import { configure } from '@riotjs/ssr'

// override the internal methods
configure({
  createDOM() {},
  cleanDOM() {}
})
Kal-Aster commented 3 years ago

That is a cool idea! Tomorrow I can work on a PR

WebReflection commented 3 years ago

I didn't want to offend you, if you feel so

I didn't, but the title of this issue coming after another one I am working on was a bit off ... there's no best DOM library, there are few choices you can pick accordingly to your needs: one is perf oriented, with the will to be as standard as possible, if perf is not too compromise, the other one is used to test WHATWG and doesn't care about perf, but it's surely closer to what a browser does.

Kal-Aster commented 3 years ago

Sure, that is why the idea of Gianluca is good: leaving the choice of which library to use to the end user.

I'm preparing the PR, I hope it'll ready for tomorrow

GianlucaGuarini commented 2 years ago

@Kal-Aster closing this issue see also https://github.com/riot/ssr/pull/30#issuecomment-932999107