dreamland.js

dreamland.js

•  •  10 updates •  14h 26m

A utilitarian javascript framework smaller than preact

(stonkers: mail.hackclub.com uses this! take a look at https://github.com/hackclub/theseus package.json...)

By Toshit

Timeline

Toshit
Toshit 26m spent working 68d ago

Did some size optimizations on the router and fixed some bugs in the JSX factory again. I'll continue with the SSR stuff in the next journey respin.

Toshit
Toshit 6m spent working 70d ago

Very small update: fixed a bug in the JSX factory causing it to set the children attribute on regular HTML elements.

Next (hopefully big) update is coming after finals (thursday pst)

Toshit
Toshit 22m spent working 73d ago

Switched dreamland to using the new JSX transform internally, with a shim for the old one. This should hopefully allow me to pass internal props via symbols to change behavior slightly for eventual SSR.

Also, I am thinking of creating a dreamland/hybrid target where you can send the UI with some other server (like rails) and tell dreamland to mount a component onto it, allowing you to use all the fancy dreamland state and syntax while still doing ssr (if you couldn't tell already this is basically for mail.hackclub.com). You could still use the dreamland JSX to add in more HTML after mounting, but the mounted component wouldn't return HTML because the HTML would come from the server prepopulated with the props and dreamland/hybrid would parse those and send them to the JSX factory for hydration. It should probably have a better name than dreamland/hybrid too.

Toshit Toshit 2 months ago

Let me know if you have any good ideas for this (or a good name lol)

Toshit
Toshit 58m spent working 75d ago

Fixed a whole bunch of bugs in the state system, css parsing, and jsx factory as I ran into them while working on https://shipwrecked.r58playz.dev ! The more I use the new state system the more I think it's awesome, especially with the helper funcs like andThen and mapEach.

Toshit
Toshit 2h spent working 77d ago

Rewrote the old router which was in a different repo and not updated for the dreamland rewrite.

The syntax is very similar to react router, just without JSX based routes for now. It's in a different bundle than the core dreamland code since a router isn't really needed to use dreamland but still in the dreamland repo/npm package because I already have everything set up and this is a fairly small project anyway.

Size is pretty good as well, but I haven't optimized it yet either. The current bundle outputs are: core for all the core stuff, router for the router, js-runtime for the tagged template HTML factory, and jsx-runtime for the shim to the new JSX transform.

Update attachment
Toshit
Toshit 2h spent working 77d ago

I rewrote the CSS system (again) because I was running into issues with @velzie's rewrite, which aimed to fix bugs in the original CSS system but caused some more. The main issue with the original implementation was that dynamic elements (ie use(...).map(x =>

)) would not have the proper scoped CSS class when passed as a child to another component.

It took a while to fix but eventually I was able to get this test working across dynamic state changes: (the numbers signify which component the element is from, 0 is the highest, 2 is the lowest; nested means it was passed as a child)

Update attachment
Toshit Toshit 3 months ago
The formatting of the code block is broken as of writing, it's not supposed to be actually parsing the HTML (vuln... it's patched now), so please ignore.

Commits: 35ac009a4e34f3ac392349efcdb4902a6ce9ab1d, c634f293159306a630a2efcd6760098a53844479, ea6f7ffdfc7aad09beb4ea571d19d2394f482802, 58da92b4ca287e76d97b3784ee91d6648718d8bd
Toshit
Toshit 2h spent working 82d ago

We realized that scope isn't actually different from cascade so we just removed it to make it simpler and avoid confusion. I also rewrote the store system so that people can make async store backings to put settings in IndexedDB or whatever. Also fixed a bunch of bugs with things like value/checked props, createElementNS, and the JSX factory's types.

Toshit Toshit 3 months ago
Commits: there's like 10 so not listing them all: aaf4fdc0a8756177e0aedcb4e2be5aaa4a69db29 to 00a60b6d4b9f1dc33d348542f9a5c7b621641925.
Size improvement: -292 bytes to 8147B
Neon Neon 3 months ago
sweet!
Toshit
Toshit 2h spent working 85d ago

Fixed a bug in :global (it was using class names that started with a number for the transformation, causing the css parsing to bug out) and did some more code golfing, reducing the bundle size by 250b to 8439b minified (preact is 11.7kb minified).

Neon Neon 3 months ago
noice
Toshit Toshit 3 months ago
Also added `value`/`checked` props, making it easier to work with inputs. Commits: 54b6a9fec44c72cda5845c5ebdd3bdfc23c8edf7, e30e0e9688bccc55ca20bfc12203af3ef1f55966, 955ae7083cef25ba50079f5c3199f21545cf554e
Toshit
Toshit 1h spent working 87d ago

Built a proper CSS selector parser to fix :global! I based it off of https://github.com/LeaVerou/parsel as it was already very tiny and allowed me to only tokenize the selector, saving even more space. I minified it even more by replacing all the token types with Symbols because I was already using them everywhere else and allowing terser to minify the fields which weren't regex groups. There's more potential for size improvements but this is pretty good for now and works well.

Toshit Toshit 3 months ago
Commits: f832d58659389f72e4c7c84086fdf7fab59535bc, 6f2834cb965700b3c37309c10cd1c50dd883b591, dbe725fc98363625ef3b01c3066b8b8637be1d8a, 5465c5e52a8e308750f71b89272899f1669e84df, 2afa92f3515bd962ffcce308d03f487ecb29a5ab
Toshit
Toshit 42m spent working 88d ago

Fixed the cascade CSS parsing (it's still not fully correct, I might have to actually start parsing it properly but idk how much of a size increase that would be), and implemented :global for cascade so that stuff that relied on the bad CSS parsing can work properly (like the shipwrecked site rewrite lol).

Also added :component due to a limitation of the :global implementation: .background :global(*) doesn't work because the implementation only supports :global at the outside of a selector, so instead you would do :global(.background:component *).

Toshit Toshit 3 months ago
Commits: fd5a6362f1010a0874baade152e9937364f9646b, 202c39954d1377e6102e5823279494d08d85af0a