Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure dev overlay uses basePath for requests #14475

Merged
merged 4 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -46,5 +46,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>
</>
)
29 changes: 27 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,28 @@ 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).toMatchInlineSnapshot(`
"pages${
process.platform === 'win32' ? '\\' : '/'
}hello.js (52:14) @ onClick

50 | id=\\"trigger-error\\"
51 | onClick={() => {
> 52 | throw new Error('oops heres an error')
| ^
53 | }}
54 | >
55 | click me for 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 @@ -349,7 +372,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