Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
364 commits
Select commit Hold shift + click to select a range
0919e45
clean up
zackradisic Sep 10, 2025
9ea2ec8
Refactor the client a lot
alii Sep 10, 2025
d984f8f
Merge branch 'ali/react' of github.com:oven-sh/bun into ali/react
alii Sep 10, 2025
20d2f38
force passing a cacheId
alii Sep 10, 2025
e503858
Fix Router navigation state handling
alii Sep 10, 2025
a63888e
Improve type safety of DOM element creation utils
alii Sep 10, 2025
39e7e55
Move `SSRResonse -> Bun.SSRResponse`
zackradisic Sep 10, 2025
0df21d7
handle scope exceptions
zackradisic Sep 10, 2025
f28670a
update
zackradisic Sep 11, 2025
6cf46e6
Merge branch 'zack/ssg-3-bun' into zack/ssg-3
zackradisic Sep 11, 2025
95cacdc
fix slop tests
zackradisic Sep 11, 2025
eafc04c
remove that
zackradisic Sep 11, 2025
bf99273
use correct allocator
zackradisic Sep 11, 2025
24b2929
update IncrementalGraph
zackradisic Sep 11, 2025
41fbeac
escape json if needed
zackradisic Sep 11, 2025
bbfac70
dev server source provider destructor
zackradisic Sep 11, 2025
db2960d
fix some C++ stuff
zackradisic Sep 11, 2025
a7e9571
fix some more stuff
zackradisic Sep 11, 2025
52c3e2e
remove dead code
zackradisic Sep 11, 2025
a3d9147
merge
zackradisic Sep 11, 2025
99df2e0
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 11, 2025
29b6faa
Make MiString
zackradisic Sep 11, 2025
208ac7f
smol changes
zackradisic Sep 11, 2025
8be4fb6
make it better
zackradisic Sep 11, 2025
1ef578a
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 11, 2025
7afcc84
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 11, 2025
b4add53
fix a bunch of typescript problems in our test suite
alii Sep 11, 2025
dca3481
remove uninit state for a store
alii Sep 11, 2025
d54ffd8
dont use dom libs
alii Sep 12, 2025
ffeb21c
add the `bun:app` module
zackradisic Sep 12, 2025
199781b
Fix banned words and package.json lint errors
Sep 12, 2025
51e18d3
try this
alii Sep 12, 2025
cae0673
load the framework
alii Sep 12, 2025
9c5c4ed
`Bun.SSRResponse` -> `import { Response } from 'bun:app'`
zackradisic Sep 12, 2025
2bd5d68
Add support for `--app` flag in CLI to run bun.app.ts or bun.app.js
alii Sep 12, 2025
d56005b
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 12, 2025
1920a7c
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 12, 2025
0ba166e
cleaning
alii Sep 13, 2025
b5c16dc
Enhance DevServer logging for framework initialization and route scan…
alii Sep 13, 2025
d4a9c7a
some helpful logs
alii Sep 13, 2025
34cfdf0
Fix
zackradisic Sep 13, 2025
56e9c92
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 13, 2025
2eb3362
use jsc call conv
zackradisic Sep 13, 2025
1a0a081
woops
zackradisic Sep 13, 2025
2166f0c
Merge branch 'main' into zack/ssg-3
zackradisic Sep 14, 2025
93007de
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into ali/react
alii Sep 15, 2025
8e659b2
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 15, 2025
704661e
remove support for builtInModules
alii Sep 15, 2025
1217e87
remove builtInModules in zig
alii Sep 15, 2025
7339d18
specify absolute path
alii Sep 15, 2025
99dd08b
Merge branch 'main' into zack/ssg-3
zackradisic Sep 15, 2025
894a654
print errors during framework resolution
alii Sep 15, 2025
ed4a887
Merge branch 'zack/ssg-3' into ali/react
alii Sep 15, 2025
bb19610
Update Bun framework to use react-server-dom-webpack and upgrade depe…
alii Sep 16, 2025
a64f073
minimize
alii Sep 16, 2025
3e798f1
type only import
alii Sep 16, 2025
28447ab
Refactor HotReloadEvent and comment out unused code in BundleV2
alii Sep 16, 2025
ecd2fed
try with redo of react-server-dom-bun
alii Sep 16, 2025
d3bdc77
types
alii Sep 16, 2025
6338d55
continue
alii Sep 16, 2025
ea78d56
bump react
alii Sep 16, 2025
d0da707
types
alii Sep 16, 2025
421a4f3
FIX the concurrent request bug
zackradisic Sep 17, 2025
916d44f
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 17, 2025
c29c69b
types
alii Sep 17, 2025
f5122bd
use import instead of class
zackradisic Sep 18, 2025
f33a852
merge
zackradisic Sep 18, 2025
731f42c
fix test
zackradisic Sep 18, 2025
e554c4e
Update bun-framework-react dependencies and imports
alii Sep 18, 2025
ce560cd
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into ali/react
alii Sep 19, 2025
e6aced6
remove
alii Sep 19, 2025
da0b090
use the specific bundles
alii Sep 19, 2025
90e68fa
use different react bundles
alii Sep 19, 2025
a47cbef
restore bundler options
alii Sep 19, 2025
bcea163
update framework def
alii Sep 19, 2025
b516eed
fix mod
alii Sep 19, 2025
a8ff3f8
move module map
alii Sep 19, 2025
dab797b
fix test
zackradisic Sep 19, 2025
b3f92b0
fix test
zackradisic Sep 19, 2025
aea7b19
Revert visitExpr
alii Sep 19, 2025
6556138
types
alii Sep 19, 2025
6e61206
remove react special case resolution
alii Sep 19, 2025
363c4a5
revert
alii Sep 19, 2025
53299d7
refactor framework definition and options interface in bun-types; rem…
alii Sep 19, 2025
53208e2
.staticRouters is not implemented
alii Sep 19, 2025
f691ea1
rm
alii Sep 19, 2025
101bcb1
there is no is_built_in_react anymore
alii Sep 19, 2025
921e357
change
alii Sep 19, 2025
0ac6b17
revert some changes
alii Sep 19, 2025
903ac7b
Refactor DevServer: remove unused bakeDebug output and clean up route…
alii Sep 19, 2025
1a19be0
remove unnecessary data output in development mode
alii Sep 19, 2025
691e731
changes
alii Sep 19, 2025
0919f23
remove
alii Sep 19, 2025
11dc2fa
revert HotReloadEvent.zig
alii Sep 19, 2025
243f365
remove old commented code
alii Sep 19, 2025
59b34ef
link
alii Sep 19, 2025
612d411
change versions
alii Sep 20, 2025
ac02036
Merge remote-tracking branch 'origin/zack/ssg-3' into ali/react
alii Sep 20, 2025
36a414c
change import to type and add error handling for synthetic modules
alii Sep 20, 2025
61b1ade
push
alii Sep 20, 2025
2701292
edit react framework
alii Sep 20, 2025
3a200e8
overlay: print err message with whitespace formatting
alii Sep 20, 2025
dbe15d3
okay fuck
zackradisic Sep 20, 2025
361cd05
move framework entrypoints
alii Sep 20, 2025
d8fa01e
basic impl
alii Sep 20, 2025
7e89ca3
link
alii Sep 20, 2025
8b7bc0f
dont attempt to resolve initial rsc payload when doing first render o…
alii Sep 20, 2025
99a80a6
changes
alii Sep 20, 2025
b17dccc
fix that
zackradisic Sep 21, 2025
cda3eb5
delete stupid slop tests
zackradisic Sep 22, 2025
9d67981
get http method
zackradisic Sep 22, 2025
0b45b9c
Add request property to bun:app module and enhance type definitions
alii Sep 22, 2025
3a23965
Merge remote-tracking branch 'origin/zack/ssg-3' into ali/react
alii Sep 22, 2025
f145d8c
Merge branch 'main' into zack/ssg-3
zackradisic Sep 22, 2025
b0d3815
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into ali/react
alii Sep 22, 2025
c07150d
types
alii Sep 22, 2025
cc84e27
changes
alii Sep 23, 2025
2894e8d
change
alii Sep 23, 2025
247629a
cleaning
alii Sep 23, 2025
fc6fdbe
rm
alii Sep 23, 2025
5e256e4
fix
zackradisic Sep 23, 2025
1b01f7c
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 23, 2025
deb3e94
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 23, 2025
e92fd08
make it work
zackradisic Sep 23, 2025
1e30570
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 23, 2025
f03a1ab
Update
zackradisic Sep 23, 2025
047eecc
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into ali/react
alii Sep 23, 2025
bade403
fix: Don't report more than once for missing "use client" calls
alii Sep 23, 2025
c85ab52
feat: report "use client" warning on more well known client hooks
alii Sep 23, 2025
43a7b65
fix
zackradisic Sep 23, 2025
f84f90c
rm .app test
alii Sep 23, 2025
bbaabed
fix: use CatchScope
alii Sep 23, 2025
a548ae7
remove default title
alii Sep 24, 2025
58ecff4
Merge branch 'main' into zack/ssg-3
zackradisic Sep 24, 2025
166e961
listen for shell
alii Sep 24, 2025
e40238f
instant crash
alii Sep 24, 2025
80c28b6
change
alii Sep 24, 2025
7282e92
try fix ci for bun-framework-react
alii Sep 24, 2025
da2be3f
cleanup
alii Sep 24, 2025
5b4b99e
Merge branch 'zack/ssg-3' into ali/react
alii Sep 24, 2025
3b2bea9
better way to escape
zackradisic Sep 24, 2025
457b4a4
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 24, 2025
bdf77f9
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into ali/react
alii Sep 24, 2025
1a1091f
alii Sep 24, 2025
c93d8cf
changes
alii Sep 24, 2025
5aa5906
Merge branch 'main' into zack/ssg-3
alii Sep 25, 2025
c64dd68
vendor react-server-dom-bun
alii Sep 25, 2025
0b0ffbf
Merge branch 'zack/ssg-3' into ali/react
alii Sep 25, 2025
c129d68
types & other changes
alii Sep 25, 2025
61519b3
reorganise
alii Sep 25, 2025
85db756
canary.3
alii Sep 25, 2025
67d2749
canary.5
alii Sep 25, 2025
c1931c1
lots of Framework interface documentation
alii Sep 25, 2025
f65d89f
changes
alii Sep 25, 2025
17fdb5b
move this
alii Sep 25, 2025
f20b0ce
tidy bake harness
alii Sep 25, 2025
fa727b2
remove
alii Sep 25, 2025
9270652
allow warnings in bun install
alii Sep 25, 2025
2ff068d
Update visitExpr.zig
Jarred-Sumner Sep 25, 2025
af3a1ff
Update BakeGlobalObject.cpp
Jarred-Sumner Sep 25, 2025
7204820
Update BakeGlobalObject.cpp
Jarred-Sumner Sep 25, 2025
4e62975
better way to do `Response.render(...)`
zackradisic Sep 25, 2025
b257967
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 25, 2025
71a5f9f
Delete console logs
zackradisic Sep 25, 2025
0cc6325
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 25, 2025
11eddb2
resolve comments
zackradisic Sep 25, 2025
891ea72
changes
alii Sep 26, 2025
2d3223c
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into ali/react
alii Sep 26, 2025
0971670
pageModule might not resolve
alii Sep 26, 2025
c2c2a16
changes
alii Sep 26, 2025
2323011
types
alii Sep 26, 2025
4f0d2a5
throw if no exports instead of silently failing
alii Sep 26, 2025
2a7e2c9
Remove unncessary dupe
zackradisic Sep 26, 2025
a2689c0
change
alii Sep 26, 2025
799248b
use vendored rsdb
alii Sep 26, 2025
1b3d0d5
regen
alii Sep 26, 2025
16360c9
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 26, 2025
472e2d3
fixes
zackradisic Sep 26, 2025
7227745
0.0.0-canary.7
alii Sep 26, 2025
678843f
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into ali/react
alii Sep 26, 2025
98b24f5
alii Sep 26, 2025
cdeb7bf
proper event loop stuff
zackradisic Sep 26, 2025
4cec2ec
changes
alii Sep 26, 2025
3fca3b9
resolve comments
zackradisic Sep 26, 2025
2474810
okie dokie
zackradisic Sep 26, 2025
de999f7
resolve more comments
zackradisic Sep 26, 2025
cd800b0
decrash
alii Sep 27, 2025
7f96bf8
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into ali/react
alii Sep 27, 2025
c62613e
better file hash
alii Sep 27, 2025
756e590
fix ban words
zackradisic Sep 27, 2025
dd9860f
Merge branch 'main' into zack/ssg-3
zackradisic Sep 27, 2025
8cd9b4e
update leaksan.supp
zackradisic Sep 27, 2025
ab579a3
less confusing
zackradisic Sep 27, 2025
49cfda1
Merge branch 'zack/ssg-3' of https://github.com/oven-sh/bun into zack…
zackradisic Sep 27, 2025
243a237
use jsc call conv
zackradisic Sep 27, 2025
b5a5fea
fix
zackradisic Sep 27, 2025
49a9dc7
fix banword
zackradisic Sep 27, 2025
971e467
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into zack/ssg-3
zackradisic Sep 27, 2025
daefbfb
Merge branch 'main' into zack/ssg-3
zackradisic Sep 27, 2025
1c6165e
fix leak
zackradisic Sep 27, 2025
d0fed20
Revert "fix leak"
zackradisic Sep 29, 2025
661a246
fix
zackradisic Sep 29, 2025
e1ad16f
Merge branch 'zack/ssg-3' of github.com:oven-sh/bun into ali/react
alii Sep 29, 2025
f43a175
use options
alii Sep 29, 2025
8d8b037
rm
alii Sep 29, 2025
1381de4
Merge branch 'main' of github.com:oven-sh/bun into ali/react
alii Sep 30, 2025
a17eb07
revert some unnecessary changes
alii Sep 30, 2025
a873152
Revert bundle_v2.zig
alii Sep 30, 2025
c534f0c
Merge branch 'main' into ali/react
alii Sep 30, 2025
65e6609
fix: updated load expectation
alii Oct 1, 2025
b2353d6
Merge branch 'main' of github.com:oven-sh/bun into ali/react
alii Oct 1, 2025
4f21950
fix production.test.ts resolving bun-framework-react
alii Oct 1, 2025
06cfe2e
bump react
alii Oct 1, 2025
3851137
unused for now
alii Oct 1, 2025
cb14f70
remove dated .auto() implementation
alii Oct 1, 2025
62b296b
message
alii Oct 1, 2025
72b7956
remove old property
alii Oct 1, 2025
fc9538b
move
alii Oct 1, 2025
69a76d4
types
alii Oct 1, 2025
f262e32
tidy
alii Oct 1, 2025
ceaab9e
tests: Fix spacing in routes test expectation
alii Oct 1, 2025
6977b36
change
alii Oct 1, 2025
2153fe4
Merge branch 'main' of github.com:oven-sh/bun into ali/react
alii Oct 2, 2025
a6d3808
[autofix.ci] apply automated fixes
autofix-ci[bot] Oct 2, 2025
86af3dd
fix test
alii Oct 3, 2025
efb508e
chore: Bump & pin React
alii Oct 3, 2025
2f02e4e
Merge branch 'main' of github.com:oven-sh/bun into ali/react
alii Oct 3, 2025
3ca89ab
remove
alii Oct 3, 2025
cc78a1b
fix: re-inject react-refresh in auto mode
alii Oct 3, 2025
ff84564
fix that
alii Oct 3, 2025
31352bc
fix test
alii Oct 3, 2025
952436f
returnIfException()
alii Oct 3, 2025
33537b6
Merge branch 'main' into ali/react
alii Oct 3, 2025
a20a718
[autofix.ci] apply automated fixes
autofix-ci[bot] Oct 3, 2025
031f124
fix: We do require react/react-dom
alii Oct 3, 2025
74f4fcf
Revert launch.json
alii Oct 3, 2025
c9b5ba1
bump builtin react-refresh
alii Oct 3, 2025
dde1f9e
pin peechy
alii Oct 3, 2025
81999c2
extend the debug timeout a little
alii Oct 3, 2025
fbd58db
changes
alii Oct 3, 2025
da5bf73
clean up args
alii Oct 3, 2025
329c793
Merge branch 'main' into ali/react
alii Oct 6, 2025
5972cf2
Merge remote-tracking branch 'origin/main' into ali/react
alii Oct 6, 2025
7dfed6b
Merge branch 'main' of github.com:oven-sh/bun into ali/react
alii Oct 7, 2025
3cb6447
fix: Merge with 1.3 new Bun.serve types
alii Oct 8, 2025
7aef153
refactor: Remove experimental types and related references from the c…
alii Oct 8, 2025
4a4a377
Merge branch 'main' into ali/react
alii Oct 8, 2025
ed1eb21
Merge branch 'main' of github.com:oven-sh/bun into ali/react
alii Oct 9, 2025
e306ac8
Merge branch 'main' into ali/react
alii Oct 20, 2025
6e3ee65
Merge remote-tracking branch 'origin' into ali/react
alii Nov 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ examples/**/* linguist-documentation

vendor/*.c linguist-vendored
vendor/brotli/** linguist-vendored
packages/bun-framework-react/vendor/** linguist-vendored -diff -merge

test/js/node/test/fixtures linguist-vendored
test/js/node/test/common linguist-vendored
Expand Down
3 changes: 2 additions & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cmake/Sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
"paths": ["src/bake/*.ts", "src/bake/*/*.{ts,css}"],
"exclude": ["src/bake/generated.ts"]
},
{
"output": "BunFrameworkReactSources.txt",
"paths": ["packages/bun-framework-react/*.{ts,tsx,js,jsx}", "packages/bun-framework-react/src/**/*.{ts,tsx,js,jsx}"]
},
{
"output": "BindgenSources.txt",
"paths": ["src/**/*.bind.ts"]
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
},
"resolutions": {
"bun-types": "workspace:packages/bun-types",
"@types/bun": "workspace:packages/@types/bun"
"@types/bun": "workspace:packages/@types/bun",
"@types/node": "24.3.1"
},
"scripts": {
"build": "bun --silent run build:debug",
Expand Down
1 change: 1 addition & 0 deletions packages/bun-framework-react/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bun-framework-react*.tgz
10 changes: 10 additions & 0 deletions packages/bun-framework-react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<img src="https://bun.com/logo.png" height="36" />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add alt text to the image for accessibility.

The image is missing alternative text, which is important for accessibility and SEO.

Apply this diff to add descriptive alt text:

-<img src="https://bun.com/logo.png" height="36" />
+<img src="https://bun.com/logo.png" alt="Bun Logo" height="36" />
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<img src="https://bun.com/logo.png" height="36" />
<img src="https://bun.com/logo.png" alt="Bun Logo" height="36" />
🧰 Tools
🪛 markdownlint-cli2 (0.18.1)

1-1: Images should have alternate text (alt text)

(MD045, no-alt-text)

🤖 Prompt for AI Agents
In packages/bun-framework-react/README.md around lines 1 to 1, the <img> tag
lacks an alt attribute which harms accessibility and SEO; update the tag to
include a descriptive alt text such as alt="Bun logo" or alt="Bun JavaScript
runtime logo" (choose the wording that best fits the repo) so screen readers and
search engines can interpret the image; apply the change by adding the alt
attribute to the existing img element.


# `bun-framework-react`

An implementation of the Bun Rendering API for React, with RSC (React Server Components)

1. `bun add bun-framework-react --dev`
2. Make a `pages/index.tsx` file, with a page component defualt export

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix typo in documentation.

Line 8 contains a typo: "defualt" should be "default".

Apply this diff to correct the typo:

-2. Make a `pages/index.tsx` file, with a page component defualt export
+2. Make a `pages/index.tsx` file, with a page component default export
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
2. Make a `pages/index.tsx` file, with a page component defualt export
2. Make a `pages/index.tsx` file, with a page component default export
🤖 Prompt for AI Agents
In packages/bun-framework-react/README.md around line 8, the word "defualt" is
misspelled; change it to "default" so the sentence reads "...with a page
component default export". Update the typo and save the README.

3. Run `bun --app`
4. Open [localhost:3000](https://localhost:3000) 🎉
32 changes: 32 additions & 0 deletions packages/bun-framework-react/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions packages/bun-framework-react/client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { onServerSideReload } from "bun:app/client";
import { hydrateRoot } from "react-dom/client";
import { initialRscPayloadThen } from "./src/client/app.ts";
import { router } from "./src/client/constants.ts";
import { Root } from "./src/client/root.tsx";

hydrateRoot(document, <Root />, {
onUncaughtError(e) {
console.error(e);
},
});

const firstPageId = Date.now();
{
history.replaceState(firstPageId, "", location.href);
initialRscPayloadThen(result => {
if (router.hasNavigatedSinceDOMContentLoaded()) return;

// Collect the list of CSS files that were added from SSR
const links = document.querySelectorAll<HTMLLinkElement>("link[data-bake-ssr]");
router.css.clear();

for (let i = 0; i < links.length; i++) {
const link = links[i];
if (!link) continue;
const href = new URL(link.href).pathname;
router.css.push(href);

// Hack: cannot add this to `cssFiles` because React owns the element, and
// it will be removed when any navigation is performed.
}

router.setCachedPage(firstPageId, {
css: [...router.css.getList()],
element: result,
});
});

if (document.startViewTransition !== undefined) {
// View transitions are used by navigations to ensure that the page rerender
// all happens in one operation. Additionally, developers may animate
// different elements. The default fade animation is disabled so that the
// out-of-the-box experience feels like there are no view transitions.
// This is done client-side because a React error will unmount all elements.
const sheet = new CSSStyleSheet();
document.adoptedStyleSheets.push(sheet);
sheet.replaceSync(":where(*)::view-transition-group(root){animation:none}");
}
}

window.addEventListener("popstate", async event => {
const state = typeof event.state === "number" ? event.state : undefined;
await router.navigate(location.href, state);
});
Comment on lines +51 to +54

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Avoid unhandled rejections in popstate handler

Event listeners ignore returned Promises. Catch navigation errors to prevent "Unhandled promise rejection" noise.

-window.addEventListener("popstate", async event => {
-  const state = typeof event.state === "number" ? event.state : undefined;
-  await router.navigate(location.href, state);
-});
+window.addEventListener("popstate", event => {
+  const state = typeof event.state === "number" ? event.state : undefined;
+  void router.navigate(location.href, state).catch(console.error);
+});
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
window.addEventListener("popstate", async event => {
const state = typeof event.state === "number" ? event.state : undefined;
await router.navigate(location.href, state);
});
window.addEventListener("popstate", event => {
const state = typeof event.state === "number" ? event.state : undefined;
void router.navigate(location.href, state).catch(console.error);
});
🤖 Prompt for AI Agents
In packages/bun-framework-react/client.tsx around lines 51 to 54, the popstate
event handler awaits router.navigate but does not catch rejections, which can
produce unhandled promise rejection noise; wrap the navigation call in a
try/catch (or append .catch(...)) and log or handle errors (include context like
the location.href and state) so any navigation failure is captured and does not
surface as an unhandled rejection.


if (import.meta.env.DEV) {
// Frameworks can call `onServerSideReload` to hook into server-side hot
// module reloading.
onServerSideReload(async () => {
const newId = Date.now();
history.replaceState(newId, "", location.href);
await router.navigate(location.href, newId);
});
}
35 changes: 35 additions & 0 deletions packages/bun-framework-react/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Framework } from "bun:app";

function resolve(specifier: string) {
return Bun.fileURLToPath(import.meta.resolve(specifier));
}

const framework: Framework = {
serverComponents: {
separateSSRGraph: true,
serverRuntimeImportSource: resolve("./vendor/react-server-dom-bun/server.node.js"),
},
reactFastRefresh: {
importSource: resolve("react-refresh/runtime"),
},
fileSystemRouterTypes: [
{
root: "pages",
clientEntryPoint: resolve("./client.tsx"),
serverEntryPoint: resolve("./server.tsx"),
extensions: [".tsx", ".jsx"],
style: "nextjs-pages",
layouts: true,
ignoreUnderscores: true,
prefix: "/",
ignoreDirs: ["node_modules", ".git"],
},
],
// bundlerOptions: {
// ssr: {
// conditions: ["react-server"],
// },
// },
};

export default framework;
36 changes: 36 additions & 0 deletions packages/bun-framework-react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "bun-framework-react",
"version": "0.0.0-canary.10",
"devDependencies": {
"@types/react": "^19.1.13",
"@types/react-dom": "^19.1.9"
},
"exports": {
".": "./index.ts",
"./package.json": "./package.json",
"./ssr.tsx": "./ssr.tsx",
"./server.tsx": "./server.tsx",
"./client.tsx": "./client.tsx",
"./*": "./src/components/*.tsx"
},
"description": "React framework integration with RSC, for the Bun Rendering API",
"files": [
"./vendor",
"./src",
"./*.ts",
"./*.tsx",
"./README.md"
],
"keywords": [
"bun",
"react",
"framework",
"bake"
],
"type": "module",
"dependencies": {
"react": "0.0.0-experimental-a757cb76-20251002",
"react-dom": "0.0.0-experimental-a757cb76-20251002",
"react-refresh": "0.0.0-experimental-a757cb76-20251002"
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import type { Bake } from "bun";
import { renderToHtml, renderToStaticHtml } from "bun-framework-react/ssr.tsx" with { bunBakeGraph: "ssr" };
import { serverManifest } from "bun:bake/server";
import * as Bake from "bun:app";
import { serverManifest } from "bun:app/server";
import type { AsyncLocalStorage } from "node:async_hooks";
import { PassThrough } from "node:stream";
import { renderToPipeableStream } from "react-server-dom-bun/server.node.unbundled.js";
import type { RequestContext } from "../hmr-runtime-server";
import type { RequestContext } from "../../src/bake/hmr-runtime-server.ts";
import { renderToPipeableStream } from "./vendor/react-server-dom-bun/server.node.unbundled.js";

function assertReactComponent(Component: any) {
function assertReactComponent(Component: unknown): asserts Component is React.JSXElementConstructor<unknown> {
if (typeof Component !== "function") {
console.log("Expected a React component", Component, typeof Component);
throw new Error("Expected a React component");
}
}

// This function converts the route information into a React component tree.
function getPage(meta: Bake.RouteMetadata & { request?: Request }, styles: readonly string[]) {
function getPage(meta: Bake.RouteMetadata & { request?: Request | undefined }, styles: readonly string[]) {
let route = component(meta.pageModule, meta.params, meta.request);

for (const layout of meta.layouts) {
const Layout = layout.default;
const Layout = layout.default as typeof layout.default & { displayName?: string };
Layout.displayName ??= "Layout";
if (import.meta.env.DEV) assertReactComponent(Layout);
route = <Layout params={meta.params}>{route}</Layout>;
}
Expand All @@ -26,7 +27,6 @@ function getPage(meta: Bake.RouteMetadata & { request?: Request }, styles: reado
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Bun + React Server Components</title>
{styles.map(url => (
// `data-bake-ssr` is used on the client-side to construct the styles array.
<link key={url} rel="stylesheet" href={url} data-bake-ssr />
Expand All @@ -37,8 +37,12 @@ function getPage(meta: Bake.RouteMetadata & { request?: Request }, styles: reado
);
}

function component(mod: any, params: Record<string, string> | null, request?: Request) {
function component(mod: any, params: Record<string, string | string[]> | null, request?: Request) {
if (!mod || !mod.default) {
throw new Error("Pages must have a default export that is a React component");
}
const Page = mod.default;

let props = {};
if (import.meta.env.DEV) assertReactComponent(Page);

Expand All @@ -51,7 +55,6 @@ function component(mod: any, params: Record<string, string> | null, request?: Re
props = method();
}

// Pass request prop if mode is 'ssr'
if (mod.mode === "ssr" && request) {
props.request = request;
}
Expand All @@ -76,7 +79,7 @@ export async function render(
const skipSSR = request.headers.get("Accept")?.includes("text/x-component");

// Check if the page module has a streaming export, default to false
const streaming = meta.pageModule.streaming ?? false;
const streaming = meta.pageModule?.streaming ?? false;

// Do not render <link> tags if the request is skipping SSR.
const page = getPage(meta, skipSSR ? [] : meta.styles);
Expand Down Expand Up @@ -104,7 +107,6 @@ export async function render(

// Mark as aborted and call the abort function
signal.aborted = err;
// @ts-expect-error
signal.abort(err);
rscPayload.destroy(err);
},
Expand Down Expand Up @@ -236,5 +238,5 @@ export const contentTypeToStaticFile = {
export interface MiniAbortSignal {
aborted: Error | undefined;
/** Caller must set `aborted` to true before calling. */
abort: () => void;
abort: (reason?: any) => void;
}
Loading