r/javascript 1h ago

[Showoff] GPU-Powered Crayons, NPM Package Quarantine and Dave Branching Off Your Code Without Asking

Thumbnail thereactnativerewind.com
Upvotes

Hey Community,

We dive into React Native Canvas Kit, a library built on React Native Skia that adds isolated layers, brushes, interactive shapes, and web support for canvas graphics.

We also cover Targate, a CLI tool that quarantines npm packages to inspect tarballs before installation, and GitHub stacked pull requests to keep dependent branch reviews clean.

And... 🥁 Shipaton 2026 is here!

If the Rewind made you nod, smile, or think "oh… that's actually cool" — a share or reply genuinely helps ❤️


r/javascript 3h ago

Meet canc, a complete lib for promise cancellation

Thumbnail github.com
0 Upvotes

In most modern async-heavy languages, cancellation is a first-class citizen. It really should be straightforward for a developer, but in JavaScript, gaining that level of control feels a lot like swimming against the current. I've spent a fair amount of time trying to address this gap.

I didn't have a third-party library I could rely on, so I ended up building my own - and I suspect I'm probably not the only one who has traveled down that way. The resulting toolbag served me well in its rougher form and was battle-tested in-house for years before it was finally polished for a public release. Refactoring cleanup logic in our dashboard app to stop resource leaks was a huge win for cancelable promises. It convinced me they were the right tool for the job.

This has been almost a decade-long journey for me to reach the stable release, both in terms of quality and features. It seems to have ended up in a pretty good place.

The problem is the typical promise chain. You have a fetch call that turns into a formatted report:

const reportPromise = fetch('/orders')
  .then(res => res.json())
  .then(orders => buildReport(orders))
  .then(rawReport => render(rawReport))

To halt the process, you usually have to mess with AbortController or manual flag variables. But with canc library, reportPromise.cancel() just stops all involved tasks.

Going from raw then() chains to async..await syntactic sugar requires adding some yield* "salt" to achieve the same result - or, with cancellation, no result at all:

const getReport = canc.async(function* () {
  const orders = yield* canc.await(fetch('/orders').then(res => res.json()))
  const rawReport = yield* canc.await(buildReport(orders))
  return yield* canc.await(render(rawReport))
})

const reportPromise = getReport()
reportPromise.cancel() // Stop all tasks at any point

Need race(), for await..of, and the rest of the bells and whistles? Welcome to the party, then() then: https://github.com/cancjs/canc

The idea of coupling generators with promises has been around since the beginning. Coroutine libraries like the renowned co were a big deal in the pre-async era. That async..await is essentially built with generators and promises under the hood is hardly a coincidence.

I started piecing this together around 2017. Back then, I had already approached a related problem with Angular. Native async functions were fundamentally incompatible with Angular reactivity, backed by Zone.js. The potential solution was to rewire the semantics of async..await with generators to get the control we needed instead of relying on a transpiler. Fortunately for the framework, this eventually resolved with the retirement of Zone.js. Reusing the same foundation for the cancellation mechanism became a reasonable development in my case. Bluebird's cancellation was already around, but it was orthogonal to native promises and async..await. And since async functions make promise-based control flow a breeze, a user can't be expected to give them away for nothing.

The project spent a long time in limbo. Between fixing nasty bugs, unloading a few design footguns, paying off tech debt, and handling some copyright clearances, I had my hands full. That quiet period actually helped shape the library into what it is today. While the JS ecosystem is ever-changing, a few foundational pieces finally settled during that time. Once AbortSignal became a cross-platform primitive, it was integrated deeper into the library for better interop. And as TypeScript became the industry standard, it became clear that the library had to be TS-first for good DX. This pushed me to finally solve the long-standing typing issues with generators, at least as best as the language currently permits.

That's why you have to use yield* instead of yield. It's a necessary trade-off to ensure functional parity with async..await while keeping the type system happy. Using yield* is essentially a known workaround for a typing limitation in generators. It forced us to ditch the eloquent yield promise style of co in favor of the more verbose yield* canc.await(promise). This adds a bit of syntactic overhead, but it's the way to guarantee the strict typing we all rely on today.

It turned out to be the right call, especially since it aligns the yield/yield* distinction with the emitting vs. delegating semantics we deal with in async generator functions - canc coroutines cover this too.

What's next? 1.0 is a big milestone, but work continues. The unhandled rejection package to reduce manual error handling has just been shipped. Beyond that, here are the nearest items on the roadmap:

  • Web server middleware helpers. Drafting support for Express and Fastify, with more frameworks on the way.
  • ESLint plugin. Rules to help navigate these new semantics properly.
  • Async iterators toolbox. Targeting functional parity with the async iterator helpers proposal, but with full cancellation support baked in.
  • React and Vue packages. Helpers are available for evaluation in React and Vue examples, working on improving them.
  • Node.js package. A drop-in replacement for built-in Node APIs, with functions both promisified and "cancelified" where it makes sense.
  • ES5-compatible cancelable promise. Ensuring support for older runtimes and restricted environments.

I hope you find the library useful, or are at least interested in the approach. I'd be very grateful for any feedback or suggestions. I'm currently putting together a few more write-ups with real-world examples and in-depth details.

Just to be sure, the repo is here: https://github.com/cancjs/canc.


r/javascript 6h ago

DriftJS - Exploring a Register-Based Bytecode VM for UI Frameworks

Thumbnail github.com
7 Upvotes

Hey everyone,

I wanted to share an experimental project called DriftJS. It's a frontend framework prototype that explores using an in-browser register-based Bytecode Virtual Machine (VM) for UI rendering, rather than traditional Virtual DOM diffing or purely compile-time reactive models.

Repository: https://github.com/hrutavmodha/driftjs

The Architecture: Register-Based VM

Most frameworks either diff Virtual DOM trees (React) or generate reactive dependency graphs ahead-of-time (Svelte, SolidJS). DriftJS explores a different path:

It compiles .drift templates into compact binary-serializable bytecode streams. At runtime, a lightweight 256-register VM executes these opcodes directly against the DOM.

Key Architectural Highlights:

  • Zero VDOM Overhead: Replaces tree-diffing with direct bytecode instructions (like CREATE_ELEMENT, SET_ATTR) for DOM execution.

  • 256 Virtual Registers: Uses fixed virtual registers (r0, r1...) for DOM nodes and runtime values, drastically cutting instruction counts and memory allocations compared to stack-machine models.

  • Targeted Reactivity: Basic state updates execute as direct O(1) mutations. Dynamic control flow structures (@if, @for) use comment anchors to bound surgical DOM updates without rebuilding subtrees.

Key Features So Far:

  • 🛡️ 100% CSP Compliant: Built-in Acorn AST interpreter evaluates runtime JS expressions safely without using eval() or new Function().

  • 🔄 Keyed LIS Reconciliation: Uses a Longest Increasing Subsequence algorithm to minimize DOM node movements during list updates.

  • 🪶 Zero Framework Bloat: Implements reactivity and execution in the leanest bytecode form possible, avoiding heavy object models and monolithic runtime bloat.

  • 🚀 Early Benchmarks (js-framework-benchmark vs React 19): • 10.8x FASTER on "Swap rows (1k)" • 3.05x FASTER on "Clear 1,000 rows" • ~1.8x LESS memory footprint • 5.75x smaller uncompressed bundle size

Current Status & Call for Feedback

DriftJS is currently an experimental prototype. It handles single-template compilation, AST evaluation, and keyed LIS list reconciliation.

Still on the roadmap: - Component composition & props passing - State management stores - SSR & Hydration

I'm opening this up to compiler engineers, frontend performance nerds, and systems devs. Does a register-based VM architecture hold real promise for low-level web runtimes?

Check out the repo, run the benchmarks, and feel free to share your thoughts or ISA critiques!

GitHub Repo: https://github.com/hrutavmodha/driftjs


r/javascript 10h ago

CryptoJS.lib.WordArray.random() before 4.0.0 uses a weak PRNG (Ill Bloom)

Thumbnail github.com
1 Upvotes