Skip to content

Commit

Permalink
chore: do not fixStacktrace
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed May 19, 2022
1 parent 67d273c commit 800aef6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 52 deletions.
5 changes: 1 addition & 4 deletions docs/guide/api-javascript.md
Expand Up @@ -92,10 +92,7 @@ interface ViteDevServer {
/**
* Load a given URL as an instantiated module for SSR.
*/
ssrLoadModule(
url: string,
options?: { fixStacktrace?: boolean }
): Promise<Record<string, any>>
ssrLoadModule(url: string): Promise<Record<string, any>>
/**
* Fix ssr error stacktrace.
*/
Expand Down
15 changes: 3 additions & 12 deletions packages/vite/src/node/server/index.ts
Expand Up @@ -199,10 +199,7 @@ export interface ViteDevServer {
/**
* Load a given URL as an instantiated module for SSR.
*/
ssrLoadModule(
url: string,
opts?: { fixStacktrace?: boolean }
): Promise<Record<string, any>>
ssrLoadModule(url: string): Promise<Record<string, any>>
/**
* Returns a fixed version of the given stack
*/
Expand Down Expand Up @@ -323,7 +320,7 @@ export async function createServer(
return transformRequest(url, server, options)
},
transformIndexHtml: null!, // to be immediately set
async ssrLoadModule(url, opts?: { fixStacktrace?: boolean }) {
async ssrLoadModule(url) {
if (!server._ssrExternals) {
let knownImports: string[] = []
const optimizedDeps = server._optimizedDeps
Expand All @@ -336,13 +333,7 @@ export async function createServer(
}
server._ssrExternals = resolveSSRExternal(config, knownImports)
}
return ssrLoadModule(
url,
server,
undefined,
undefined,
opts?.fixStacktrace
)
return ssrLoadModule(url, server, undefined, undefined)
},
ssrFixStacktrace(e) {
if (e.stack) {
Expand Down
5 changes: 0 additions & 5 deletions packages/vite/src/node/ssr/__tests__/ssrModuleLoader.spec.ts
Expand Up @@ -22,9 +22,4 @@ test('always throw error when evaluating an wrong SSR module', async () => {
expectedErrors.forEach((error) => {
expect(error?.message).toContain(THROW_MESSAGE)
})
expect(spy).toBeCalledTimes(1)
const [firstParameter] = spy.mock.calls[0]
expect(firstParameter).toContain('Error when evaluating SSR module')
expect(firstParameter).toContain(THROW_MESSAGE)
spy.mockClear()
})
35 changes: 4 additions & 31 deletions packages/vite/src/node/ssr/ssrModuleLoader.ts
Expand Up @@ -20,7 +20,6 @@ import {
ssrImportMetaKey,
ssrModuleExportsKey
} from './ssrTransform'
import { rebindErrorStacktrace, ssrRewriteStacktrace } from './ssrStacktrace'

interface SSRContext {
global: typeof globalThis
Expand All @@ -35,8 +34,7 @@ export async function ssrLoadModule(
url: string,
server: ViteDevServer,
context: SSRContext = { global },
urlStack: string[] = [],
fixStacktrace?: boolean
urlStack: string[] = []
): Promise<SSRModule> {
url = unwrapId(url).replace(NULL_BYTE_PLACEHOLDER, '\0')

Expand All @@ -49,13 +47,7 @@ export async function ssrLoadModule(
return pending
}

const modulePromise = instantiateModule(
url,
server,
context,
urlStack,
fixStacktrace
)
const modulePromise = instantiateModule(url, server, context, urlStack)
pendingModules.set(url, modulePromise)
modulePromise
.catch(() => {
Expand All @@ -71,8 +63,7 @@ async function instantiateModule(
url: string,
server: ViteDevServer,
context: SSRContext = { global },
urlStack: string[] = [],
fixStacktrace?: boolean
urlStack: string[] = []
): Promise<SSRModule> {
const { moduleGraph } = server
const mod = await moduleGraph.ensureEntryFromUrl(url, true)
Expand Down Expand Up @@ -143,13 +134,7 @@ async function instantiateModule(
if (pendingDeps.length === 1) {
pendingImports.set(url, pendingDeps)
}
const mod = await ssrLoadModule(
dep,
server,
context,
urlStack,
fixStacktrace
)
const mod = await ssrLoadModule(dep, server, context, urlStack)
if (pendingDeps.length === 1) {
pendingImports.delete(url)
} else {
Expand Down Expand Up @@ -206,18 +191,6 @@ async function instantiateModule(
)
} catch (e) {
mod.ssrError = e
if (e.stack && fixStacktrace !== false) {
const stacktrace = ssrRewriteStacktrace(e.stack, moduleGraph)
rebindErrorStacktrace(e, stacktrace)
server.config.logger.error(
`Error when evaluating SSR module ${url}:\n${stacktrace}`,
{
timestamp: true,
clear: server.config.clearScreen,
error: e
}
)
}
throw e
}

Expand Down

0 comments on commit 800aef6

Please sign in to comment.