Skip to content

Commit 0a3fa7e

Browse files
committed
chore: stacktrace demo
1 parent df7774b commit 0a3fa7e

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

packages/vite/src/node/server/environments/rolldown.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,12 @@ function reactRefreshPlugin(): rolldown.Plugin {
336336
},
337337
},
338338
handler(code, id) {
339-
return [
340-
`const [$RefreshSig$, $RefreshReg$] = __react_refresh_transform_define(${JSON.stringify(id)})`,
341-
code,
342-
`__react_refresh_transform_setupHot(module.hot)`,
343-
].join(';')
339+
const output = new MagicString(code)
340+
output.prepend(
341+
`const [$RefreshSig$, $RefreshReg$] = __react_refresh_transform_define(${JSON.stringify(id)});`,
342+
)
343+
output.append(`;__react_refresh_transform_setupHot(module.hot);`)
344+
return { code: output.toString(), map: output.generateMap() }
344345
},
345346
},
346347
}

playground/rolldown-dev-react/src/app.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { useState } from 'react'
1+
import React from 'react'
22
// @ts-expect-error no type
33
import virtualTest from 'virtual:test'
44
// @ts-expect-error no type
55
import testAlias from 'test-alias'
6+
import { throwError } from './error'
67

78
export function App() {
8-
const [count, setCount] = useState(0)
9+
const [count, setCount] = React.useState(0)
910

1011
return (
1112
<div>
@@ -16,6 +17,8 @@ export function App() {
1617
</button>
1718
<pre>[virtual] {virtualTest}</pre>
1819
<pre>[alias] {testAlias}</pre>
20+
{/* TODO: app.tsx source map is slightly off? */}
21+
<button onClick={() => throwError()}>stacktrace</button>
1922
</div>
2023
</div>
2124
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// random new lines
3+
//
4+
export function throwError() {
5+
//
6+
// and more
7+
//
8+
throw new Error('boom')
9+
}

0 commit comments

Comments
 (0)