Skip to content

Commit b233b75

Browse files
fix
1 parent 11f3f38 commit b233b75

3 files changed

Lines changed: 40 additions & 3 deletions

File tree

‎.changeset/add-rsbuild-start-support.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
'@tanstack/react-start': patch
33
'@tanstack/solid-start': patch
4-
'@tanstack/start-plugin-core': patch
4+
'@tanstack/start-plugin-core': minor
55
'@tanstack/react-start-rsc': patch
66
'@tanstack/router-plugin': patch
77
'@tanstack/router-utils': patch

‎packages/start-plugin-core/src/rsbuild/import-protection.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { resolve as resolvePath } from 'node:path'
22

3+
import { extname } from 'node:path'
4+
35
import { normalizePath } from 'vite'
46

57
import {
@@ -449,6 +451,33 @@ function getModuleFile(module: RspackModule): string {
449451
return normalizeFilePath(getModuleResource(module) ?? module.identifier())
450452
}
451453

454+
const IMPORT_PROTECTION_PARSEABLE_EXTENSIONS = new Set([
455+
'.ts',
456+
'.tsx',
457+
'.mts',
458+
'.cts',
459+
'.js',
460+
'.jsx',
461+
'.mjs',
462+
'.cjs',
463+
])
464+
465+
function isImportProtectionSourceFile(file: string | undefined): boolean {
466+
if (!file) {
467+
return false
468+
}
469+
470+
const extension = extname(normalizeFilePath(file))
471+
return (
472+
extension.length > 0 &&
473+
IMPORT_PROTECTION_PARSEABLE_EXTENSIONS.has(extension)
474+
)
475+
}
476+
477+
function isImportProtectionSourceModule(module: RspackModule): boolean {
478+
return isImportProtectionSourceFile(getModuleResource(module))
479+
}
480+
452481
function addTransformResult(
453482
cache: Map<string, TransformResult>,
454483
key: string,
@@ -790,6 +819,10 @@ async function getMarkerKindForFile(opts: {
790819
markerKindCache: Map<string, Promise<'server' | 'client' | undefined>>
791820
file: string
792821
}): Promise<'server' | 'client' | undefined> {
822+
if (!isImportProtectionSourceFile(opts.file)) {
823+
return undefined
824+
}
825+
793826
let cached = opts.markerKindCache.get(opts.file)
794827
if (!cached) {
795828
cached = (async () => {
@@ -1359,7 +1392,7 @@ export function registerImportProtection(
13591392
: () => Promise.resolve(undefined),
13601393
)
13611394
const allModules = Array.from(context.compilation.modules)
1362-
const relevantModules = allModules
1395+
const relevantModules = allModules.filter(isImportProtectionSourceModule)
13631396

13641397
const provider = await buildTransformResultProvider({
13651398
modules: relevantModules,

‎packages/start-plugin-core/src/rsbuild/plugin.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ export function tanStackStartRsbuild(
206206
// ---------------------------------------------------------------
207207
registerStartCompilerTransforms(api, {
208208
framework: corePluginOpts.framework,
209-
root: resolvedStartConfig.root || process.cwd(),
209+
// modifyRsbuildConfig copies rsbuildConfig.root into resolvedStartConfig.root,
210+
// so defer this read until transform time instead of falling back to
211+
// process.cwd() during plugin setup.
212+
root: () => resolvedStartConfig.root || process.cwd(),
210213
providerEnvName: serverFnProviderEnv,
211214
generateFunctionId:
212215
normalizedStartPluginOpts.serverFns?.generateFunctionId,
@@ -237,6 +240,7 @@ export function tanStackStartRsbuild(
237240
root: resolvedStartConfig.root || process.cwd(),
238241
getConfig,
239242
serverFnsById,
243+
providerEnvName: serverFnProviderEnv,
240244
ssrIsProvider,
241245
serializationAdapters: corePluginOpts.serializationAdapters,
242246
getDevClientEntryUrl: (publicBase: string) =>

0 commit comments

Comments
 (0)