In SSR the same app runs for multiple users, globally declared state works great in the browser but have several problems specially in SSR:
For Qwik is critically important to serialize, so applications can resume.
{value: XXX}
Applications should never rely on the render function being called, Qwik will ensure that the template matches the DOM, but it deserves its right not avoid calling the render function.
Other reactive libraries introduces exotic new APIs to achieve reactivity, different libraries make different tradeoffs:
Qwik already introduces exotic APIs:
Writing templates should be as natural as possible, just like you would in react. I will argue that react is the most natural one, because it's the most naive, the transform is very 1 to 1 of what the original code does.
Authoring of components should not have to make assuptions about how the component is going to be used.
Writting async code is hard:
At Qwik anything that gives stronger guaranties to async code is part of the scope of the framework:
Enable developers to get full benefit of async programming but without the negative side effects.
Developers should be able to write their custom utils, their custom component$()
, custom state tools, custom hooks, custom $
methods, custom events…
Ie, the compiler can introduce magic, but the magic should not be unique to internal methods.
Svelte suffers from this problem.
Qwik does not need a build step to run an app, all the compiler tooling is merely an optimization step that enable better performance and serialization.
Qwik cares about building sites, that includes JS, HTML and CSS. Qwik is opiniated about how styling should work in a site.
While we encourage developers to discover new patterns, the core team have strong opinions about not emiting extra JS to solve problems that are already solved by CSS, CSS variables and scoping.
Unidirectional data flow is usually a good practice, but Qwik will not enforce this, it's up to third party libraries built on top of qwik primitives to stablish new restrictions.
For Qwik, props and context is used to pass stores/signals down the tree, but reactivity flows freely.
The context API (useContextProvider()
and useContext()
) is the only API for DI in Qwik. Parents components can inject context accessible by any descendant.
The render function must return syncronously a JSX tree, ie, the render function can not return a Promise, however, the render tree might contain promises or lazy loaded components.
Even thought the qwik render is fully async, the DOM writes will be committed to the DOM in a fully sync way:
Every qwik app is a HTML-container, notice the <html q:container="paused">
, multiple containers can live within the same document, they can even be nested by state objects can not live in two containers at the same time.
Inter container communication is still a work in progress, but it will follow a message-passing paradigm, not memory-sharing.
Ie, we could even support reactivity across container by keeping two containers syncronized, rather than actually sharing the same reactive object.