Skip to content

Commit 717dfb6

Browse files
authored
[Backport] Revert "Fix tracing of server actions imported by client components (#78968) (#82167)
This backports #82161 to our next-15-4 release branch
1 parent 6372ba0 commit 717dfb6

File tree

8 files changed

+0
-139
lines changed

8 files changed

+0
-139
lines changed

packages/next/src/build/webpack-config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2015,7 +2015,6 @@ export default async function getBaseWebpackConfig(
20152015
appDirEnabled: hasAppDir,
20162016
traceIgnores: [],
20172017
compilerType,
2018-
swcLoaderConfig: swcDefaultLoader,
20192018
}
20202019
),
20212020
// Moment.js is an extremely popular library that bundles large locale files

packages/next/src/build/webpack/plugins/next-trace-entrypoints-plugin.ts

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ import picomatch from 'next/dist/compiled/picomatch'
1818
import { getModuleBuildInfo } from '../loaders/get-module-build-info'
1919
import { getPageFilePath } from '../../entries'
2020
import { resolveExternal } from '../../handle-externals'
21-
import swcLoader, { type SWCLoaderOptions } from '../loaders/next-swc-loader'
2221
import { isMetadataRouteFile } from '../../../lib/metadata/is-metadata-route'
2322
import { getCompilationSpan } from '../utils'
24-
import { isClientComponentEntryModule } from '../loaders/utils'
2523

2624
const PLUGIN_NAME = 'TraceEntryPointsPlugin'
2725
export const TRACE_IGNORES = [
@@ -139,10 +137,6 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
139137
private traceIgnores: string[]
140138
private esmExternals?: NextConfigComplete['experimental']['esmExternals']
141139
private compilerType: CompilerNameValues
142-
private swcLoaderConfig: {
143-
loader: string
144-
options: Partial<SWCLoaderOptions>
145-
}
146140

147141
constructor({
148142
rootDir,
@@ -153,7 +147,6 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
153147
traceIgnores,
154148
esmExternals,
155149
outputFileTracingRoot,
156-
swcLoaderConfig,
157150
}: {
158151
rootDir: string
159152
compilerType: CompilerNameValues
@@ -163,7 +156,6 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
163156
traceIgnores?: string[]
164157
outputFileTracingRoot?: string
165158
esmExternals?: NextConfigComplete['experimental']['esmExternals']
166-
swcLoaderConfig: TraceEntryPointsPlugin['swcLoaderConfig']
167159
}) {
168160
this.rootDir = rootDir
169161
this.appDir = appDir
@@ -174,7 +166,6 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
174166
this.traceIgnores = traceIgnores || []
175167
this.tracingRoot = outputFileTracingRoot || rootDir
176168
this.compilerType = compilerType
177-
this.swcLoaderConfig = swcLoaderConfig
178169
}
179170

180171
// Here we output all traced assets and webpack chunks to a
@@ -409,18 +400,6 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
409400
}
410401
})
411402

412-
const readOriginalSource = (path: string) => {
413-
return new Promise<string | Buffer>((resolve) => {
414-
compilation.inputFileSystem.readFile(path, (err, result) => {
415-
if (err) {
416-
// we can't throw here as that crashes build un-necessarily
417-
return resolve('')
418-
}
419-
resolve(result || '')
420-
})
421-
})
422-
}
423-
424403
const readFile = async (
425404
path: string
426405
): Promise<Buffer | string | null> => {
@@ -429,60 +408,6 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance {
429408
// map the transpiled source when available to avoid
430409
// parse errors in node-file-trace
431410
let source: Buffer | string = mod?.originalSource?.()?.buffer()
432-
433-
try {
434-
// fallback to reading raw source file, this may fail
435-
// due to unsupported syntax but best effort attempt
436-
let usingOriginalSource = false
437-
if (!source || isClientComponentEntryModule(mod)) {
438-
source = await readOriginalSource(path)
439-
usingOriginalSource = true
440-
}
441-
const sourceString = source.toString()
442-
443-
// If this is a client component we need to trace the
444-
// original transpiled source not the client proxy which is
445-
// applied before this plugin is run due to the
446-
// client-module-loader
447-
if (
448-
usingOriginalSource &&
449-
// don't attempt transpiling CSS or image imports
450-
path.match(/\.(tsx|ts|js|cjs|mjs|jsx)$/)
451-
) {
452-
let transformResolve: (result: string) => void
453-
let transformReject: (error: unknown) => void
454-
const transformPromise = new Promise<string>(
455-
(resolve, reject) => {
456-
transformResolve = resolve
457-
transformReject = reject
458-
}
459-
)
460-
461-
// TODO: should we apply all loaders except the
462-
// client-module-loader?
463-
swcLoader.apply(
464-
{
465-
resourcePath: path,
466-
getOptions: () => {
467-
return this.swcLoaderConfig.options
468-
},
469-
async: () => {
470-
return (err: unknown, result: string) => {
471-
if (err) {
472-
return transformReject(err)
473-
}
474-
return transformResolve(result)
475-
}
476-
},
477-
},
478-
[sourceString, undefined]
479-
)
480-
source = await transformPromise
481-
}
482-
} catch {
483-
/* non-fatal */
484-
}
485-
486411
return source || ''
487412
}
488413

test/production/app-dir/action-tracing/action-tracing.test.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

test/production/app-dir/action-tracing/app/action.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

test/production/app-dir/action-tracing/app/layout.tsx

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/production/app-dir/action-tracing/app/page.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/production/app-dir/action-tracing/data.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/production/app-dir/action-tracing/next.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)