Skip to content

Commit

Permalink
Ensure dev overlay uses basePath for requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Jun 23, 2020
1 parent 1f125f8 commit b3cf533
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ export const CodeFrame: React.FC<CodeFrameProps> = function CodeFrame({
params.append(key, (stackFrame[key] ?? '').toString())
}

self.fetch(`/__nextjs_launch-editor?${params.toString()}`).then(
() => {},
() => {
// TODO: report error
}
)
self
.fetch(
`${
process.env.__NEXT_ROUTER_BASEPATH || ''
}/__nextjs_launch-editor?${params.toString()}`
)
.then(
() => {},
() => {
// TODO: report error
}
)
}, [stackFrame])

// TODO: make the caret absolute
Expand Down
18 changes: 12 additions & 6 deletions packages/react-dev-overlay/src/internal/container/RuntimeError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ const CallStackFrame: React.FC<{
params.append(key, (f[key] ?? '').toString())
}

self.fetch(`/__nextjs_launch-editor?${params.toString()}`).then(
() => {},
() => {
// TODO: report error
}
)
self
.fetch(
`${
process.env.__NEXT_ROUTER_BASEPATH || ''
}/__nextjs_launch-editor?${params.toString()}`
)
.then(
() => {},
() => {
// TODO: report error
}
)
}, [hasSource, f])

return (
Expand Down
11 changes: 8 additions & 3 deletions packages/react-dev-overlay/src/internal/helpers/stack-frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ export function getOriginalStackFrame(
const controller = new AbortController()
const tm = setTimeout(() => controller.abort(), 3000)
const res = await self
.fetch(`/__nextjs_original-stack-frame?${params.toString()}`, {
signal: controller.signal,
})
.fetch(
`${
process.env.__NEXT_ROUTER_BASEPATH || ''
}/__nextjs_original-stack-frame?${params.toString()}`,
{
signal: controller.signal,
}
)
.finally(() => {
clearTimeout(tm)
})
Expand Down
8 changes: 8 additions & 0 deletions test/integration/basepath/pages/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,13 @@ export default () => (
</Link>
<div id="base-path">{useRouter().basePath}</div>
<div id="pathname">{useRouter().pathname}</div>
<div
id="trigger-error"
onClick={() => {
throw new Error('oops heres an error')
}}
>
click me for error
</div>
</>
)
17 changes: 15 additions & 2 deletions test/integration/basepath/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
File,
nextStart,
initNextServerScript,
getRedboxSource,
hasRedbox,
} from 'next-test-utils'
import fs, {
readFileSync,
Expand All @@ -32,7 +34,16 @@ jest.setTimeout(1000 * 60 * 2)
const appDir = join(__dirname, '..')

const runTests = (context, dev = false) => {
if (!dev) {
if (dev) {
it('should render error in dev overlay correctly', async () => {
const browser = await webdriver(context.appPort, '/docs/hello')
await browser.elementByCss('#trigger-error').click()
expect(await hasRedbox(browser)).toBe(true)

const errorSource = await getRedboxSource(browser)
expect(errorSource).toContain('oops heres an error')
})
} else {
it('should add basePath to routes-manifest', async () => {
const routesManifest = await fs.readJSON(
join(appDir, '.next/routes-manifest.json')
Expand Down Expand Up @@ -317,7 +328,9 @@ describe('basePath development', () => {

beforeAll(async () => {
context.appPort = await findPort()
server = await launchApp(join(__dirname, '..'), context.appPort)
server = await launchApp(join(__dirname, '..'), context.appPort, {
env: { __NEXT_TEST_WITH_DEVTOOL: 1 },
})
})
afterAll(async () => {
await killApp(server)
Expand Down

0 comments on commit b3cf533

Please sign in to comment.