npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bun-rsc

v0.0.19

Published

Ultra minimalist React server component implementation using bun. Absolutely experimental and messy.

Downloads

3

Readme

bun-rsc

Ultra minimalist React server component implementation using bun. Absolutely experimental and messy.

Heavily inspired by:

  • https://github.com/bholmesdev/simple-rsc
  • https://github.com/hex2f/marz
  • https://github.com/lubieowoce/tangle

Getting started

Installation

bun i bun-rsc

You first route

Bun-rsc is based on the file system router that Bun provides which is itself based on the Nextjs Page router.

First create a pages folder which will contain all the routes, then create a home.tsx file. It will create the /home url.

In each view you have to export a default react component, for example:

export default function Page() {
  return <p>My first route !</p>;
}

The framework comes with almost no custom api's. Everything RSC related is documented on the react docs.

Usage

Routing

The framework uses Bun's FileSystemRouter, which is the Nextjs pages router.

Meta data

If you want to change the title description and favicon you can export a meta const from your page file:

import type {Meta} from "bun-rsc"

export const meta: Meta = {
    title: "My blog"
    description: "The description of my blog"
    icon: "favicon.png"
}

The favicon will be searched in the public folder.

Middlewares

If you want to execute something at each request you can create a middleware.ts file in your src folder. This file should export a default function of type MiddlewareType:

// src/middleware.ts
import { type RequestType } from "bun-rsc";

export default ({request, params, searchParams}: RequestType) => {
    if (Math.random() > 0.5) {
        return Response("Redirected to example.com", 302, {
            Location: "https://example.com"
        })
    }
}

Bootstrap scripts

If you want to execute something before the server starts you can create a bootstrap.ts file in your src folder. This file should export a default function of type BootstrapType:

// src/bootstrap.ts
import createDb from "fake-db"

export default () => {
    createDb()
}

Current limitations

Server actions limitations

the "use server" directive is only supported at the top level of the module:

// addTodo.ts
"use server";
import {db} from "./db";

export async function addTodo(formData: FormData) {
  return db.todos.add(formData.get("text"));
}
// TodoList.tsx
import {addTodo} from "./addTodo";

export function TodoList() {
  return (
    <div>
      <form action={addTodo}>
        <input type="text" name="text" />
        <button type="submit">Add</button>
      </form>
    </div>
  );
}

Dev mode

The dev mode only provides a basic file watcher which sends a web socket message and make the browser reload. It's not as advanced as the vite's dev mode.