Skip to content

Commit

Permalink
chore: stacktrace demo
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Nov 12, 2024
1 parent df7774b commit 0a3fa7e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
11 changes: 6 additions & 5 deletions packages/vite/src/node/server/environments/rolldown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,12 @@ function reactRefreshPlugin(): rolldown.Plugin {
},
},
handler(code, id) {
return [
`const [$RefreshSig$, $RefreshReg$] = __react_refresh_transform_define(${JSON.stringify(id)})`,
code,
`__react_refresh_transform_setupHot(module.hot)`,
].join(';')
const output = new MagicString(code)
output.prepend(
`const [$RefreshSig$, $RefreshReg$] = __react_refresh_transform_define(${JSON.stringify(id)});`,
)
output.append(`;__react_refresh_transform_setupHot(module.hot);`)
return { code: output.toString(), map: output.generateMap() }
},
},
}
Expand Down
7 changes: 5 additions & 2 deletions playground/rolldown-dev-react/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useState } from 'react'
import React from 'react'
// @ts-expect-error no type
import virtualTest from 'virtual:test'
// @ts-expect-error no type
import testAlias from 'test-alias'
import { throwError } from './error'

export function App() {
const [count, setCount] = useState(0)
const [count, setCount] = React.useState(0)

return (
<div>
Expand All @@ -16,6 +17,8 @@ export function App() {
</button>
<pre>[virtual] {virtualTest}</pre>
<pre>[alias] {testAlias}</pre>
{/* TODO: app.tsx source map is slightly off? */}
<button onClick={() => throwError()}>stacktrace</button>
</div>
</div>
)
Expand Down
9 changes: 9 additions & 0 deletions playground/rolldown-dev-react/src/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// random new lines
//
export function throwError() {
//
// and more
//
throw new Error('boom')
}

0 comments on commit 0a3fa7e

Please sign in to comment.