News for hackers. Stuff that matters.
Re:Jest not recommended to be used in Node.js due to instanc... by fathyb on Friday June 30, 2023 @10:05PM (#36545581)
`instanceof Array` is a famous JavaScript footgun you should not use anyway. The same happens when sharing objects with an `iframe` (aka "cross-realm objects"). This is why `Array.isArray` exists.

That said, Jest used to be so good when it was first released, and got gradually slower and more complex. Same with Yarn.

I hope React won't face the same fate. I loved integrating the recent suspense and async rendering features. It made my app feel so much better by removing loading flickers with no architectural changes.

Re:Jest not recommended to be used in Node.js due to instanc... by CSMastermind on Friday June 30, 2023 @10:32PM (#36545776)
npm took up most of yarn's significant changes to the point where I switched back years ago.

I think the Jest situation is a little different as it was the incumbent not the challenger.

React is similar in the it's become an incumbent, though probably with less marketshare. Ironically I believe the lack of a virtual DOM is a big selling point for Svelte (sp?) which my frontend developers are really excited about.

Re:Jest not recommended to be used in Node.js due to instanc... by pcthrowaway on Saturday July 01, 2023 @06:11AM (#36548532)
I mostly use npm, but does npm have anything like yarn's workspaces or ability to patch dependencies with project-specific changes?

Those are the "killer features" for yarn IMO, and why I think a lot of projects using it would have friction moving to npm

Re:Jest not recommended to be used in Node.js due to instanc... by uallo on Saturday July 01, 2023 @06:57AM (#36548770)
Re:Jest not recommended to be used in Node.js due to instanc... by meese712 on Friday June 30, 2023 @11:01PM (#36545991)
Think the biggest slow down is from it running all the test suites in isolation in separate contexts (think that's the right word). I got frustrated with how slow our frontend tests were one day like 4 years ago and wrote a hacky jest runtime that reused the context unless it detected jest.mock or jest.spy or timer stuff in the file it was on. It speed it up by 2x with cache cleared. It was still pretty slow though...

There was also an existing issue opened requesting this to be built in by a lot of people and facebook said lol no.

Re:Jest not recommended to be used in Node.js due to instanc... by afavour on Friday June 30, 2023 @11:18PM (#36546092)
In a way React has already had the same fate. It really astounds me that react-dom is >100KB big while the API-compatible Preact is something like 7KB.

There are edge cases where you can't just drop it in directly as a replacement but you can very, very many times. Really makes me wonder what React is doing with that extra 93KB of JS, it's not actually even that fast compared to other frontend frameworks.

Re:Jest not recommended to be used in Node.js due to instanc... by Uehreka on Friday June 30, 2023 @11:39PM (#36546239)
OK, hold up, I’ve been hearing this line forever and I’m here to hold it to account:

> the API-compatible Preact is something like 7KB

Something is up here. Either Preact is not in fact API-compatible (in which case people should stop saying this), or the React devs are dummies who have never thought of Preact’s architecture or looked at its open source code (I rank this unlikely) or there’s somehow some other catch that no one talks about.

Which is it? Why doesn’t React just use Preact’s architecture if it’s so lightweight? What is Preact actually giving up?

Re:Jest not recommended to be used in Node.js due to instanc... by Inviz on Friday June 30, 2023 @11:48PM (#36546308)
It's fully api compatible pre-fiber. in fact it has more apis in some regards.
Re:Jest not recommended to be used in Node.js due to instanc... by tcpipchip on Sunday July 09, 2023 @06:16PM (#36659528)
Hi Did have success on littlefs on stm32 ? On arduino ? Please, contact me [email protected] PS: sorry if I post here
Re:Jest not recommended to be used in Node.js due to instanc... by Inviz on Thursday July 13, 2023 @10:35AM (#36709805)
I did have some success with it. I used their generic config way to hook up fro block writing/erasing and implemented those parts in the os i was writing. However one thing I was not a fan of is that its IO is synchronous, so you have to use some sort of coroutines/multitasking unless you're ok with blocking
Re:Jest not recommended to be used in Node.js due to instanc... by gedy on Saturday July 01, 2023 @12:04AM (#36546445)
From memory, Preact doesn't use synthetic events system like React and its runtime is much smaller. It can't be used generically like React can in mobile (React Native) or similar though because of this
Re:Jest not recommended to be used in Node.js due to instanc... by afavour on Saturday July 01, 2023 @12:15AM (#36546515)
There are definitely differences here and there. One I can remember from a year or so ago is that Preact deprecated support for string refs while React still supports them (though the docs point out they intend to deprecate IIRC).

Honestly to my mind the biggest thing is that bundle size just isn’t a priority for the React team. A sibling comment pointed out that React does a lot to correctly handle SVGs. Good to have, obviously, but what percentage of React users are making interactive SVGs? Probably not a whole lot. If they wanted to the React folks could break that out into a react-svg module or something and save some KB. But they don’t want to.

To my mind React these days is the enterprise software of the frontend. It’s big, it’s bulky, but it does absolutely everything with a minimum of fuss. They have a one size fits all approach and they’re not willing to deviate from it.

Re:Jest not recommended to be used in Node.js due to instanc... by fathyb on Saturday July 01, 2023 @12:26AM (#36546585)
> what percentage of React users are making interactive SVGs

Every single app I worked on for the past 5 years did. `mui` icons are SVG for example, and it's common practice to embed SVG as components to avoid the HTTP requests overhead and allow for theming through props.

Re:Jest not recommended to be used in Node.js due to instanc... by josephg on Saturday July 01, 2023 @04:50AM (#36548145)
Most people who embed svgs aren’t looking to make them interactive though. I think I’ve attached event handlers to internal elements in an svg maybe once in my entire career.
Re:Jest not recommended to be used in Node.js due to instanc... by pcthrowaway on Saturday July 01, 2023 @06:08AM (#36548514)
Things like the sparkline charts on npmjs (e.g. https://www.npmjs.com/package/npm ) are interactive SVGs. I think they're pretty common for data visualizations of all kinds
Re:Jest not recommended to be used in Node.js due to instanc... by josephg on Saturday July 01, 2023 @08:42AM (#36549499)
Sure, but data visualisations make up a tiny percentage of websites.
Re:Jest not recommended to be used in Node.js due to instanc... by afavour on Saturday July 01, 2023 @10:47AM (#36550694)
That’s a great example of what I’m talking about: it would be the perfect place to bring in a react-svg module. Vast majority of sites don’t use sparkline so the SVG stuff is unused.
Re:Jest not recommended to be used in Node.js due to instanc... by afavour on Saturday July 01, 2023 @09:12AM (#36549719)
That’s not what I’m talking about though: those aren’t interactive. You could dangerouslySetInnerHTML with them (arguably you should, it’s a waste of VDOM otherwise) and they’d be just fine.
Re:Jest not recommended to be used in Node.js due to instanc... by orangepanda on Saturday July 01, 2023 @02:46AM (#36547387)
Preact takes the King Bumi approach to API compatibility - by sometimes doing nothing.

The syntax may be compatible, but the semantics are not. For example, it doesn’t support react's concurrency features; transitions are just empty wrappers.

Re:Jest not recommended to be used in Node.js due to instanc... by franciscop on Friday June 30, 2023 @11:36PM (#36546219)
I wrote a jQuery (30kb) alternative called Umbrella JS (2.6kb) and based on my experience and if I had to guess, probably most of the rest of React's size is in compatibility stuff. Like making sure events work uniformly across browsers, I remember that making everything work with SVGs was also a big milestone, normalizing events (e.g. we have synthetic events which are basically React's events on top of the normal DOM events), etc. An astute/old fashion dev will realize that React's onChange actually behaves like `addEventListener('input')` and not really like `addEventListener('change')`, since the latter only triggers on blur and not on each keystroke.

I strongly believe React team is shooting themselves on the foot by not making Error Boundaries into Hooks. If they did, someone could create a Preact 2.0 so to speak that is like React but purely functional (no classes). But since we don't have that, and error handling IS an important part of React, any react alternative would have to implement classes fully as well, which might retract many from even trying to create a React alternative (I don't think myself smart enough to do a React alternative properly, but I'd certainly tried if they did this).

Re:Jest not recommended to be used in Node.js due to instanc... by acemarke on Friday June 30, 2023 @11:46PM (#36546291)
There's actually a recent PR up for a `<Catch>` component:

- https://github.com/facebook/react/pull/26854

Re:Jest not recommended to be used in Node.js due to instanc... by awayto on Saturday July 01, 2023 @01:18AM (#36546863)
I wonder if error boundary components/functionality are an anti-pattern. They invite the developer to create components which expect to fail. Even basic hide/show logic is better than expecting devs to orchestrate unified error handling across the app.
Re:Jest not recommended to be used in Node.js due to instanc... by solardev on Saturday July 01, 2023 @12:56PM (#36552103)
What's wrong with components that expect to fail? Don't you need some way to notify users of predictable problems?
Re:Jest not recommended to be used in Node.js due to instanc... by strogonoff on Saturday July 01, 2023 @01:16AM (#36546851)
It’s often cheaper to couple things tightly. Abstractions and interfaces have costs. However, they also have benefits. Perhaps React and Preact is one such example.

React is a tiny fully agnostic library that does components, props, hooks and all that jazz. You can use it anywhere, from DOM to CLI. To tie it to DOM, a separate library exists—named, unimaginatively, ReactDOM—and that’s where the 100KB heft comes in.

Preact is the opposite: smaller, but coupled to DOM. The architecture probably doesn’t facilitate cool stuff like render components to embedded LCD[0], and even to do SSR you would have to add extra libraries.

[0] https://github.com/doodlewind/react-ssd1306/blob/master/docs...

Re:Jest not recommended to be used in Node.js due to instanc... by acemarke on Saturday July 01, 2023 @01:37AM (#36546979)
It's somewhere in between.

React as a lib and architecture _is_ platform-agnostic. The core logic is defined in the `react-reconciler` package. It contains all the implementation of rendering components, diffing trees, managing state, and running effects, as well as all the "Suspense" implementation.

However, the way `react-reconciler` works is that it's built _into_ each platform-specific renderer implementation. So, the size of `react-dom` is actually the size of `react-reconciler` + all the DOM-specific behavior.

A quick check of https://bundlejs.com/?q=react-reconciler suggests it's about 100K minified. https://bundlejs.com/?q=react-dom is 138K, so that tells me that the DOM-specific logic is 38K.

Re:Jest not recommended to be used in Node.js due to instanc... by aledalgrande on Saturday July 01, 2023 @03:23AM (#36547630)
Seeing Preact mentioned, just wanted to give a shoutout to one of the authors, Marvin, an ex colleague. Absolutely amazing dev and person.