How Bun Makes Building React Apps Simpler & Faster

Rate this content
Bookmark

Bun’s builtin JSX transpiler, hot reloads on the server, JSX prop punning, macro api, automatic package installs, console.log JSX support, 4x faster serverside rendering and more make Bun the best runtime for building React apps

This talk has been presented at React Day Berlin 2022, check out the latest edition of this React Conference.

FAQ

Yes, BUN natively supports JSX and includes an automatic JSX/TypeScript transpiler. JSX is even enabled for .JS files, and BUN can automatically transpile NPM packages that use JSX.

In BUN v0.3.0, automatic NPM package installs were added, allowing you to import packages without running an install step if there is no node modules folder. It uses a shared global cache, saving disk space and installation time.

BUN run is an NPM package JSON scripts runner that starts package JSON scripts 30 times faster than NPM.

BUN install is an NPM package manager that installs NPM packages 20 times faster than any other NPM client available today.

BUN is a modern all-in-one JavaScript runtime environment designed to start fast, achieve new levels of performance, be a complete tool, and serve as a drop-in replacement for Node.js.

BUN dev is a front-end development server built into BUN that starts in 4 milliseconds.

Upcoming features for BUN include an AST plugin API, native Windows support, a production-optimized bundler and minifier, and easier deployment to production.

The main focus is to stabilize BUN's runtime and improve Node.js compatibility. There is also a need for better documentation and examples, as well as adding missing features like workspace and Git support to BUN install.

BUN has built-in support for hot module reloading on the server, allowing for immediate page reloads as code changes are made.

BUN has an extremely optimized React server-side renderer that makes server-side rendering in BUN four times faster compared to Node.js.

Jarred Sumner
Jarred Sumner
9 min
05 Dec, 2022

Comments

Sign in or register to post your comment.
Video Summary and Transcription
BUN is a modern all-in-one JavaScript runtime environment that achieves new levels of performance. It includes BUN dev, a fast front-end dev server, BUN install, a speedy package manager, and BUN run, a fast package runner. BUN supports JSX, has optimized React server-side rendering, and offers hot module reloading on the server. The priorities for BUN include stability, node compatibility, documentation improvement, missing features in BUN install, AST plugin API, native Windows support, Bundler and Minifier optimization, and easier deployment to production. BUN's AST plugin API allows for bundle-time JavaScript execution and embedding code, potentially inspiring new frameworks.

1. Introduction to BUN

Short description:

BUN is a modern all-in-one JavaScript runtime environment that starts fast and achieves new levels of performance. It includes BUN dev, a front-end dev server that starts in 4 milliseconds, BUN install, an NPM package manager that installs packages 20 times faster than other clients, and BUN run, an NPM package JSON scripts runner that starts scripts 30 times faster. BUN also supports JSX, has an optimized React server-side render, and offers hot module reloading on the server.

My name's Jared, and I'm going to talk about BUN. BUN is a modern all-in-one JavaScript runtime environment. It's designed to start fast, to achieve new levels of performance, to be a great and complete tool, and to be a drop-in replacement for Node.js.

BUN dev is a front-end dev server that starts in 4 milliseconds. It's a command that's built into BUN. BUN install is an NPM package manager, and it installs NPM packages 20 times faster than any other NPM client that exists today. BUN run is an NPM package JSON scripts runner, and it starts package JSON scripts 30 times faster than NPM.

In BUN v0.3.0, we added automatic NPM package installs to BUN's JavaScript runtime. That means you can just import packages and they install. There's no—you don't have to actually run an install step. This is automatically enabled when you—there is no node modules folder. So it still works with node modules, it just means when you don't have node modules, if you have a quick script that you just want to run and you don't want to have to deal with installing packages, it just works. The other thing that's really interesting about that is you can—you don't—because you don't need a node modules folder, you can just—it saves a lot of disk space and it saves you a lot of time because you don't have to spend this time installing the packages. It uses a shared global cache.

In BUN, JSX is natively supported. There's an automatic JSX slash TypeScript transpiler, JSX is even enabled for .JS files by the way, and you can also have npm packages which use JSX and BUN will just automatically transpile it. You can console.log JSX, you can do JSX prop punting and we have an extremely optimized React server-side render.

This is what it looks like when you console.log a JSX element in BUN. You can see that instead of printing the object representation with the symbols and all that stuff, it actually just pretty prints it like HTML a little bit. You can see it still preserves this is a function, or it highlights the component to be blue instead of green to indicate that it's an element versus a component. And then this is what JSX prop hunting looks like in BOTnets. There's more than one name for this, but the basic idea is that instead of having to type if the property name is the same identifier as the value, you can just emit the value. So that way, it's the equivalent of object destructuring syntax, but for JSX. I don't think there are other tools that support this yet. In the next version of React, they're adding a new bun streaming server render, and that helps make bun three and a half times faster at server-side rendering compared to when using the server.browser build, which is the one that bun currently uses. Overall, this adds up to four times faster server-side rendering in bun compared to node.

This benchmark here is a Hello World benchmark for a very simple React app. If you've used any framework in the past, for building front-end stuff with React, you've probably used hot module reloading. Usually hot module reloading is something that exists on the client, it's run in browsers. But in bun, bun has built-in support for hot module reloading on the server.

2. BUN Hot Reload Demo

Short description:

BUN allows for hot reloading on the server, using render to readable stream and the React API. It supports JSX in JS files and has built-in support for web socket servers. Bunn also provides an API for sending files.

So, here's a quick demo. This is a page that's already loaded. Keep in mind, this is running on the server. It's actually reloading the whole page on the server here. We have it do this hot reload as I type. You can see just how fast this is in the video here. I'm typing and it's immediately reloading. And that's what it looks like, you can see that it's using render to readable stream, the react API to render this react component. You can also see that it's doing JSX but it's a JS file. We have a little web socket here to send over the new styles, which web socket server is also built in support in Bunn. This is an API for sending a file in Bunn. So that's a little bit about Bunn dash dash hot.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Vite: Rethinking Frontend Tooling
JSNation Live 2021JSNation Live 2021
31 min
Vite: Rethinking Frontend Tooling
Top Content
Vite is a next-generation build tool that leverages native ES modules for improved performance. It eliminates the need for bundling and improves hot module replacement. Vite provides an opinionated default configuration while still allowing advanced customization through plugins. It is framework agnostic and can be used for React and other applications. Vite is being adopted by Next.js and Create React App, and integration with Nuxt 3 offers significant speed improvements.
A Guide to React Rendering Behavior
React Advanced 2022React Advanced 2022
25 min
A Guide to React Rendering Behavior
Top Content
This transcription provides a brief guide to React rendering behavior. It explains the process of rendering, comparing new and old elements, and the importance of pure rendering without side effects. It also covers topics such as batching and double rendering, optimizing rendering and using context and Redux in React. Overall, it offers valuable insights for developers looking to understand and optimize React rendering.
React Compiler - Understanding Idiomatic React (React Forget)
React Advanced 2023React Advanced 2023
33 min
React Compiler - Understanding Idiomatic React (React Forget)
Top Content
Watch video: React Compiler - Understanding Idiomatic React (React Forget)
Joe Savona
Mofei Zhang
2 authors
The Talk discusses React Forget, a compiler built at Meta that aims to optimize client-side React development. It explores the use of memoization to improve performance and the vision of Forget to automatically determine dependencies at build time. Forget is named with an F-word pun and has the potential to optimize server builds and enable dead code elimination. The team plans to make Forget open-source and is focused on ensuring its quality before release.
Speeding Up Your React App With Less JavaScript
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
Top Content
Watch video: Speeding Up Your React App With Less JavaScript
Mishko, the creator of Angular and AngularJS, discusses the challenges of website performance and JavaScript hydration. He explains the differences between client-side and server-side rendering and introduces Quik as a solution for efficient component hydration. Mishko demonstrates examples of state management and intercommunication using Quik. He highlights the performance benefits of using Quik with React and emphasizes the importance of reducing JavaScript size for better performance. Finally, he mentions the use of QUIC in both MPA and SPA applications for improved startup performance.
React Concurrency, Explained
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
Top Content
Watch video: React Concurrency, Explained
React 18's concurrent rendering, specifically the useTransition hook, optimizes app performance by allowing non-urgent updates to be processed without freezing the UI. However, there are drawbacks such as longer processing time for non-urgent updates and increased CPU usage. The useTransition hook works similarly to throttling or bouncing, making it useful for addressing performance issues caused by multiple small components. Libraries like React Query may require the use of alternative APIs to handle urgent and non-urgent updates effectively.
SolidJS: Why All the Suspense?
JSNation 2023JSNation 2023
28 min
SolidJS: Why All the Suspense?
Top Content
Suspense is a mechanism for orchestrating asynchronous state changes in JavaScript frameworks. It ensures async consistency in UIs and helps avoid trust erosion and inconsistencies. Suspense boundaries are used to hoist data fetching and create consistency zones based on the user interface. They can handle loading states of multiple resources and control state loading in applications. Suspense can be used for transitions, providing a smoother user experience and allowing prioritization of important content.

Workshops on related topic

React Performance Debugging Masterclass
React Summit 2023React Summit 2023
170 min
React Performance Debugging Masterclass
Top Content
Featured WorkshopFree
Ivan Akulov
Ivan Akulov
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
Building WebApps That Light Up the Internet with QwikCity
JSNation 2023JSNation 2023
170 min
Building WebApps That Light Up the Internet with QwikCity
Featured WorkshopFree
Miško Hevery
Miško Hevery
Building instant-on web applications at scale have been elusive. Real-world sites need tracking, analytics, and complex user interfaces and interactions. We always start with the best intentions but end up with a less-than-ideal site.
QwikCity is a new meta-framework that allows you to build large-scale applications with constant startup-up performance. We will look at how to build a QwikCity application and what makes it unique. The workshop will show you how to set up a QwikCitp project. How routing works with layout. The demo application will fetch data and present it to the user in an editable form. And finally, how one can use authentication. All of the basic parts for any large-scale applications.
Along the way, we will also look at what makes Qwik unique, and how resumability enables constant startup performance no matter the application complexity.
Using CodeMirror to Build a JavaScript Editor with Linting and AutoComplete
React Day Berlin 2022React Day Berlin 2022
86 min
Using CodeMirror to Build a JavaScript Editor with Linting and AutoComplete
Top Content
WorkshopFree
Hussien Khayoon
Kahvi Patel
2 authors
Using a library might seem easy at first glance, but how do you choose the right library? How do you upgrade an existing one? And how do you wade through the documentation to find what you want?
In this workshop, we’ll discuss all these finer points while going through a general example of building a code editor using CodeMirror in React. All while sharing some of the nuances our team learned about using this library and some problems we encountered.
Next.js 13: Data Fetching Strategies
React Day Berlin 2022React Day Berlin 2022
53 min
Next.js 13: Data Fetching Strategies
Top Content
WorkshopFree
Alice De Mauro
Alice De Mauro
- Introduction- Prerequisites for the workshop- Fetching strategies: fundamentals- Fetching strategies – hands-on: fetch API, cache (static VS dynamic), revalidate, suspense (parallel data fetching)- Test your build and serve it on Vercel- Future: Server components VS Client components- Workshop easter egg (unrelated to the topic, calling out accessibility)- Wrapping up
React Performance Debugging
React Advanced 2023React Advanced 2023
148 min
React Performance Debugging
Workshop
Ivan Akulov
Ivan Akulov
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
Build Peer-to-Peer Applications with Pear Runtime
JSNation 2024JSNation 2024
152 min
Build Peer-to-Peer Applications with Pear Runtime
WorkshopFree
David Mark Clements
David Mark Clements
Learn how to rapidly build peer-to-peer applications with Pear Runtime. No servers required. Understand peer-to-peer paradigms and construct applications from well-defined building blocks. This workshop will cover how to create both Desktop and Terminal applications (with discussion for Mobile) that work entirely peer-to-peer from anywhere in the world. By the end of this workshop you should know how to build a new type of highly scalable application with entirely reduced infrastructural costs (~0) along with suitable architectures and best practices for peer-to-peer applications. From the creator of Pear Runtime and the company that brings us keet.io. Table of content:- Introducing Pear- Initial Q & A- Getting Setup- Creating a Pear Desktop Application- Sharing a Pear Application- Running a Pear Application- Creating a Pear Terminal Application- Releasing a Pear Application- Architectural Discussions- Wrap-up Q & A