Skip to content

Commit dda463c

Browse files
fix: Split Start plugin core (#7249)
1 parent 1248e44 commit dda463c

22 files changed

Lines changed: 218 additions & 63 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@tanstack/start-plugin-core': minor
3+
'@tanstack/react-start': patch
4+
'@tanstack/react-start-rsc': patch
5+
'@tanstack/solid-start': patch
6+
'@tanstack/vue-start': patch
7+
---
8+
9+
Split Start plugin core bundler APIs into explicit Vite and Rsbuild subpaths so projects only need the bundler they use. Mark both `vite` and `@rsbuild/core` peers as optional where Start exposes both integrations.

‎e2e/react-start/import-protection/tests/import-protection.spec.ts‎

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,33 @@ import type { Violation } from './violations.utils'
66
import type { Page } from '@playwright/test'
77

88
const toolchain = process.env.E2E_TOOLCHAIN ?? 'vite'
9+
const fixtureRoot = path.resolve(import.meta.dirname, '..')
10+
const workspaceRoot = path.resolve(import.meta.dirname, '../../../..')
11+
12+
function stripLocation(value: string): string {
13+
return value.replace(/:\d+:\d+$/, '')
14+
}
15+
16+
function normalizeKeyPath(value: string): string {
17+
let normalized = stripLocation(value).replace(/\\/g, '/')
18+
const normalizedFixtureRoot = fixtureRoot.replace(/\\/g, '/')
19+
const normalizedWorkspaceRoot = workspaceRoot.replace(/\\/g, '/')
20+
21+
if (normalized.startsWith(`${normalizedFixtureRoot}/`)) {
22+
normalized = normalized.slice(normalizedFixtureRoot.length + 1)
23+
} else if (normalized.startsWith(`${normalizedWorkspaceRoot}/`)) {
24+
normalized = normalized.slice(normalizedWorkspaceRoot.length + 1)
25+
}
26+
27+
normalized = normalized.replace(
28+
/^packages\/react-start\/dist\/esm\/(.+)$/,
29+
'@tanstack/react-start/$1',
30+
)
31+
normalized = normalized.replace(/\.[cm]?[tj]sx?$/, '')
32+
normalized = normalized.replace(/\/index$/, '')
33+
34+
return normalized
35+
}
936

1037
async function readViolations(
1138
type: 'build' | 'dev' | 'dev.cold' | 'dev.warm',
@@ -571,7 +598,7 @@ test('warm run produces violations', async () => {
571598
expect(warm.length).toBeGreaterThan(0)
572599
})
573600

574-
test('warm run detects the same unique violations as cold run', async () => {
601+
test('warm run detects every unique cold-run violation', async () => {
575602
const cold = await readViolations('dev.cold')
576603
const warm = await readViolations('dev.warm')
577604

@@ -581,13 +608,29 @@ test('warm run detects the same unique violations as cold run', async () => {
581608
// the `.ts` extension) because different detection code-paths fire.
582609
// Normalize to the resolved path (without extension) for a stable key.
583610
const normalizeSpec = (v: Violation) =>
584-
(v.resolved ?? v.specifier).replace(/\.[cm]?[tj]sx?$/, '')
611+
normalizeKeyPath(v.resolved ?? v.specifier)
612+
const normalizeImporter = (v: Violation) => {
613+
const importer = stripLocation(v.importer)
614+
const leafTraceFile = v.trace.at(-1)?.file
615+
616+
if (
617+
leafTraceFile &&
618+
!importer.includes('/') &&
619+
normalizeKeyPath(leafTraceFile).endsWith(normalizeKeyPath(importer))
620+
) {
621+
return normalizeKeyPath(leafTraceFile)
622+
}
623+
624+
return normalizeKeyPath(importer)
625+
}
585626
const uniqueKey = (v: Violation) =>
586-
`${v.envType}|${v.type}|${normalizeSpec(v)}|${v.importer.replace(/:.*/, '')}`
627+
`${v.envType}|${v.type}|${normalizeSpec(v)}|${normalizeImporter(v)}`
587628

588629
const coldUniq = [...new Set(cold.map(uniqueKey))].sort()
589-
const warmUniq = [...new Set(warm.map(uniqueKey))].sort()
590-
expect(warmUniq).toEqual(coldUniq)
630+
const warmUniq = new Set(warm.map(uniqueKey))
631+
const missingFromWarm = coldUniq.filter((key) => !warmUniq.has(key))
632+
633+
expect(missingFromWarm).toEqual([])
591634
})
592635

593636
test('warm run traces include line numbers', async () => {

‎e2e/react-start/start-manifest/tests/start-manifest.spec.ts‎

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ async function getBackgroundColor(testId: string, page: Page) {
2727
.evaluate((element) => getComputedStyle(element).backgroundColor)
2828
}
2929

30+
async function getBorderTopColor(testId: string, page: Page) {
31+
return page
32+
.getByTestId(testId)
33+
.evaluate((element) => getComputedStyle(element).borderTopColor)
34+
}
35+
3036
function getStylesheetHrefsFromHtml(html: string) {
3137
return Array.from(
3238
html.matchAll(/<link[^>]+rel="stylesheet"[^>]+href="([^"]+)"/g),
@@ -357,11 +363,11 @@ test('shared widget CSS stays applied when navigating from static to lazy route'
357363
const widget = page.getByTestId('shared-widget')
358364
await expect(widget).toBeVisible()
359365
expect(await getBackgroundColor('shared-widget', page)).toBe(SHARED_WIDGET_BG)
360-
expect(
361-
await widget.evaluate(
362-
(element) => getComputedStyle(element).borderTopColor,
363-
),
364-
).toBe(SHARED_WIDGET_BORDER)
366+
await expect
367+
.poll(() => getBorderTopColor('shared-widget', page), {
368+
timeout: 5_000,
369+
})
370+
.toBe(SHARED_WIDGET_BORDER)
365371

366372
await expect(page.getByTestId('lazy-css-static-hydrated')).toBeVisible()
367373

@@ -391,6 +397,7 @@ test('shared widget CSS stays applied when navigating from lazy to static route'
391397

392398
await page.getByTestId('nav-/lazy-css-static').click()
393399
await page.waitForURL('**/lazy-css-static')
400+
await expect(page.getByTestId('lazy-css-static-hydrated')).toBeVisible()
394401

395402
const widget = page.getByTestId('shared-widget')
396403
await expect(widget).toBeVisible()
@@ -399,11 +406,11 @@ test('shared widget CSS stays applied when navigating from lazy to static route'
399406
timeout: 5_000,
400407
})
401408
.toBe(SHARED_WIDGET_BG)
402-
expect(
403-
await widget.evaluate(
404-
(element) => getComputedStyle(element).borderTopColor,
405-
),
406-
).toBe(SHARED_WIDGET_BORDER)
409+
await expect
410+
.poll(() => getBorderTopColor('shared-widget', page), {
411+
timeout: 5_000,
412+
})
413+
.toBe(SHARED_WIDGET_BORDER)
407414
})
408415

409416
test('shared widget CSS is applied on direct navigation to lazy route', async ({
@@ -421,11 +428,11 @@ test('shared widget CSS is applied on direct navigation to lazy route', async ({
421428
timeout: 5_000,
422429
})
423430
.toBe(SHARED_WIDGET_BG)
424-
expect(
425-
await widget.evaluate(
426-
(element) => getComputedStyle(element).borderTopColor,
427-
),
428-
).toBe(SHARED_WIDGET_BORDER)
431+
await expect
432+
.poll(() => getBorderTopColor('shared-widget', page), {
433+
timeout: 5_000,
434+
})
435+
.toBe(SHARED_WIDGET_BORDER)
429436
})
430437

431438
test('shared widget CSS persists after navigating away from lazy and back', async ({

‎packages/react-start-rsc/src/plugin/vite.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { fileURLToPath } from 'node:url'
22
import path from 'pathe'
3-
import { createVirtualModule } from '@tanstack/start-plugin-core'
3+
import { createVirtualModule } from '@tanstack/start-plugin-core/vite'
44
import type {
55
TanStackStartVitePluginCoreOptions,
66
ViteRscForwardSsrResolverStrategy,
7-
} from '@tanstack/start-plugin-core'
7+
} from '@tanstack/start-plugin-core/vite'
88
import type { PluginOption, UserConfig } from 'vite'
99

1010
const isClientEnvironment = (env: { config: { consumer: string } }) =>

‎packages/react-start/package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@
176176
},
177177
"@vitejs/plugin-rsc": {
178178
"optional": true
179+
},
180+
"vite": {
181+
"optional": true
179182
}
180183
},
181184
"devDependencies": {

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
2-
START_ENVIRONMENT_NAMES,
2+
RSBUILD_ENVIRONMENT_NAMES,
33
tanStackStartRsbuild,
4-
} from '@tanstack/start-plugin-core'
4+
} from '@tanstack/start-plugin-core/rsbuild'
55
import { reactStartDefaultEntryPaths } from './shared'
6-
import type { TanStackStartRsbuildPluginCoreOptions } from '@tanstack/start-plugin-core/rsbuild/types'
7-
import type { TanStackStartRsbuildInputConfig } from '@tanstack/start-plugin-core'
6+
import type {
7+
TanStackStartRsbuildInputConfig,
8+
TanStackStartRsbuildPluginCoreOptions,
9+
} from '@tanstack/start-plugin-core/rsbuild'
810
import type { RsbuildPlugin } from '@rsbuild/core'
911

1012
export function tanstackStart(
@@ -15,7 +17,7 @@ export function tanstackStart(
1517
let corePluginOpts: TanStackStartRsbuildPluginCoreOptions = {
1618
framework: 'react',
1719
defaultEntryPaths: reactStartDefaultEntryPaths,
18-
providerEnvironmentName: START_ENVIRONMENT_NAMES.server,
20+
providerEnvironmentName: RSBUILD_ENVIRONMENT_NAMES.server,
1921
ssrIsProvider: true,
2022
}
2123

@@ -47,7 +49,7 @@ function configureRscRsbuild(): {
4749
serializationAdapters: TanStackStartRsbuildPluginCoreOptions['serializationAdapters']
4850
} {
4951
return {
50-
providerEnvironmentName: START_ENVIRONMENT_NAMES.server,
52+
providerEnvironmentName: RSBUILD_ENVIRONMENT_NAMES.server,
5153
serializationAdapters: [
5254
{
5355
client: {

‎packages/react-start/src/plugin/vite.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {
22
START_ENVIRONMENT_NAMES,
33
tanStackStartVite,
4-
} from '@tanstack/start-plugin-core'
4+
} from '@tanstack/start-plugin-core/vite'
55
import type {
66
TanStackStartViteInputConfig,
77
TanStackStartVitePluginCoreOptions,
8-
} from '@tanstack/start-plugin-core'
8+
} from '@tanstack/start-plugin-core/vite'
99
import {
1010
configureRsc,
1111
reactStartRscVitePlugin,

‎packages/solid-start/package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@
135135
"peerDependenciesMeta": {
136136
"@rsbuild/core": {
137137
"optional": true
138+
},
139+
"vite": {
140+
"optional": true
138141
}
139142
},
140143
"bin": {

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
2-
START_ENVIRONMENT_NAMES,
2+
RSBUILD_ENVIRONMENT_NAMES,
33
tanStackStartRsbuild,
4-
} from '@tanstack/start-plugin-core'
4+
} from '@tanstack/start-plugin-core/rsbuild'
55
import { solidStartDefaultEntryPaths } from './shared'
6-
import type { TanStackStartRsbuildPluginCoreOptions } from '@tanstack/start-plugin-core/rsbuild/types'
7-
import type { TanStackStartRsbuildInputConfig } from '@tanstack/start-plugin-core'
6+
import type {
7+
TanStackStartRsbuildInputConfig,
8+
TanStackStartRsbuildPluginCoreOptions,
9+
} from '@tanstack/start-plugin-core/rsbuild'
810
import type { RsbuildPlugin } from '@rsbuild/core'
911

1012
export function tanstackStart(
@@ -13,7 +15,7 @@ export function tanstackStart(
1315
const corePluginOpts: TanStackStartRsbuildPluginCoreOptions = {
1416
framework: 'solid',
1517
defaultEntryPaths: solidStartDefaultEntryPaths,
16-
providerEnvironmentName: START_ENVIRONMENT_NAMES.server,
18+
providerEnvironmentName: RSBUILD_ENVIRONMENT_NAMES.server,
1719
ssrIsProvider: true,
1820
rsbuild: {
1921
environments: {

‎packages/solid-start/src/plugin/vite.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {
22
START_ENVIRONMENT_NAMES,
33
tanStackStartVite,
4-
} from '@tanstack/start-plugin-core'
4+
} from '@tanstack/start-plugin-core/vite'
55
import type {
66
TanStackStartViteInputConfig,
77
TanStackStartVitePluginCoreOptions,
8-
} from '@tanstack/start-plugin-core'
8+
} from '@tanstack/start-plugin-core/vite'
99
import { solidStartDefaultEntryPaths } from './shared'
1010
import type { PluginOption } from 'vite'
1111

0 commit comments

Comments
 (0)