Skip to content

shared TSRX semantic analysis during client, server, universal-render, and Volar compilation - #230

Merged
trueadm merged 5 commits into
mainfrom
analyze
Jul 22, 2026
Merged

trueadm merged 5 commits into
mainfrom
analyze

Conversation

@leonidaz

@leonidaz leonidaz commented Jul 22, 2026 •

Copy link
Copy Markdown
Collaborator

Note

Medium Risk
Touches the core compile pipeline for every TSRX module and adds new semantic failures that can break existing apps; Volar and bundler integration changes need careful regression testing.

Overview
Wires analyzeTsrx from @tsrx/core into the main compile path (client and server), universal compilation (reusing a parsed AST when possible), and the Volar language service. Unused template output is now a normal compile failure and shows up as a recoverable editor diagnostic in Volar.

The bundler stops pre-running hydrate-boundary rewrites and native-change analysis on its own; it passes hydrate context via the module id query string and calls compile / compileForBundler, which always validate authored source first. Eval train manifest rows pick up an updated overlayLockfileHash from the dependency bump.

Reviewed by Cursor Bugbot for commit 4284561. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
octane-website Ready Ready Preview, Comment Jul 22, 2026 2:49am
octane-website-mcp Ready Ready Preview, Comment Jul 22, 2026 2:49am

Request Review

@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 22, 2026 01:10 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 22, 2026 01:10 Inactive

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Hydrate prepass skips authored analysis
    • Bundler transforms now pass the authored AST into compile-time semantic analysis, preserving direct-compile diagnostics and authored locations across client extraction and server fallback stripping.

Create PR

Or push these changes by commenting:

@cursor push 712e2f4d95
Preview (712e2f4d95)
diff --git a/packages/octane/src/compiler/bundler.js b/packages/octane/src/compiler/bundler.js
--- a/packages/octane/src/compiler/bundler.js
+++ b/packages/octane/src/compiler/bundler.js
@@ -883,17 +883,13 @@
 				};
 			}
 			const hasRendererBoundaries = Object.keys(this.renderers.boundaries).length > 0;
-			const nativeChangeAnalysis = analyzeNativeChangeDiagnostics(
-				parseModule(code, filename),
-				code,
-				filename,
-				{
-					dom: renderer.target === 'dom',
-					renderer,
-					rendererBoundaries: this.renderers.boundaries,
-					rendererRegistry: this.renderers.registry,
-				},
-			);
+			const authoredAst = parseModule(code, filename);
+			const nativeChangeAnalysis = analyzeNativeChangeDiagnostics(authoredAst, code, filename, {
+				dom: renderer.target === 'dom',
+				renderer,
+				rendererBoundaries: this.renderers.boundaries,
+				rendererRegistry: this.renderers.registry,
+			});
 			const nativeChangeDiagnostics = nativeChangeAnalysis.diagnostics;
 			const hydratePreparation =
 				environment === 'client'
@@ -903,6 +899,7 @@
 			const out = compile(compileSource, filename, {
 				__hydratePrepared: true,
 				__hydrateBoundaryModule: typeof hydratePreparation?.boundaryPath === 'string',
+				__analysisAst: authoredAst,
 				__nativeChangeDiagnostics: nativeChangeDiagnostics,
 				...(hydratePreparation === null && !hasRendererBoundaries
 					? { __nativeChangeAnalysis: nativeChangeAnalysis }

diff --git a/packages/octane/src/compiler/compile.js b/packages/octane/src/compiler/compile.js
--- a/packages/octane/src/compiler/compile.js
+++ b/packages/octane/src/compiler/compile.js
@@ -4175,7 +4175,7 @@
  * Compile a .tsrx source string into JS targeting `octane`.
  * @param {string} source
  * @param {string} filename
- * @param {{ hmr?: boolean | 'vite' | 'webpack', mode?: 'client' | 'server', dev?: boolean, profile?: boolean, profileFilename?: string, autoMemo?: boolean, inlineHookMemo?: boolean, renderer?: { id: string, module: string, target: 'dom' | 'universal', server?: string }, rendererBoundaries?: Readonly<Record<string, Readonly<Record<string, { ownerRenderer: string, childRenderer: string, prop: string, server?: string }>>>>, rendererRegistry?: Readonly<Record<string, { module: string, target: 'dom' | 'universal', server?: string }>>, clientOnlyImports?: readonly unknown[], __hydratePrepared?: boolean, __hydrateBoundaryModule?: boolean, __nativeChangeDiagnostics?: readonly unknown[], __nativeChangeAnalysis?: { diagnostics: readonly unknown[], classifications: Map<number, string> } }} [options] —
+ * @param {{ hmr?: boolean | 'vite' | 'webpack', mode?: 'client' | 'server', dev?: boolean, profile?: boolean, profileFilename?: string, autoMemo?: boolean, inlineHookMemo?: boolean, renderer?: { id: string, module: string, target: 'dom' | 'universal', server?: string }, rendererBoundaries?: Readonly<Record<string, Readonly<Record<string, { ownerRenderer: string, childRenderer: string, prop: string, server?: string }>>>>, rendererRegistry?: Readonly<Record<string, { module: string, target: 'dom' | 'universal', server?: string }>>, clientOnlyImports?: readonly unknown[], __analysisAst?: any, __hydratePrepared?: boolean, __hydrateBoundaryModule?: boolean, __nativeChangeDiagnostics?: readonly unknown[], __nativeChangeAnalysis?: { diagnostics: readonly unknown[], classifications: Map<number, string> } }} [options] —
  *   `dev: true` emits client hydration source-location metadata (per-component
  *   `__s.locs`/`__s.locFile`) and, in server mode, source-located native-element
  *   scopes for invalid HTML nesting diagnostics. Both are strictly gated so
@@ -4288,9 +4288,15 @@
 	if (mode !== 'client' && mode !== 'server') {
 		throw new Error(`Unknown compile mode "${mode}" — expected 'client' or 'server'.`);
 	}
-	const analyzedAst = parseModule(source, filename);
-	analyzeTsrx(analyzedAst, filename);
-	return compileInternal(source, filename, options, analyzedAst, mode);
+	const analysisAst = options?.__analysisAst ?? parseModule(source, filename);
+	analyzeTsrx(analysisAst, filename);
+	return compileInternal(
+		source,
+		filename,
+		options,
+		options?.__analysisAst === undefined ? analysisAst : null,
+		mode,
+	);
 }
 
 function compileInternal(source, filename, options, analyzedAst, mode) {

diff --git a/packages/octane/tests/hydrate-compiler.test.ts b/packages/octane/tests/hydrate-compiler.test.ts
--- a/packages/octane/tests/hydrate-compiler.test.ts
+++ b/packages/octane/tests/hydrate-compiler.test.ts
@@ -579,6 +579,47 @@
 
 	it.each([
 		{
+			environment: 'client' as const,
+			source: `import { Hydrate } from 'octane';
+export function App() @{
+  <Hydrate when={true}>
+    {(() => { <span>unused child</span>; return <b>used</b>; })()}
+  </Hydrate>
+}`,
+		},
+		{
+			environment: 'server' as const,
+			source: `import { Hydrate } from 'octane';
+export function App() @{
+  <Hydrate when={true} fallback={<aside>{(() => { <span>unused fallback</span>; return 'loading'; })()}</aside>}>
+    <b>used</b>
+  </Hydrate>
+}`,
+		},
+	])(
+		'reports authored template diagnostics for $environment transforms',
+		({ environment, source }) => {
+			const getError = (run: () => unknown) => {
+				try {
+					run();
+				} catch (error) {
+					return error;
+				}
+				return null;
+			};
+			const direct = getError(() => compile(source, FILE, { mode: environment })) as any;
+			const bundled = getError(() => compiler().transform(source, FILE, { environment })) as any;
+
+			expect(direct).toMatchObject({ code: 'tsrx-forgotten-statement-container' });
+			expect(bundled).toMatchObject({
+				code: direct.code,
+				loc: direct.loc,
+			});
+		},
+	);
+
+	it.each([
+		{
 			code: 'OCTANE_HYDRATE_FUNCTION_CHILD',
 			source: `import { Hydrate } from 'octane'; export function App() @{ <Hydrate when={gate}>{() => <b />}</Hydrate> }`,
 		},

You can send follow-ups to the cloud agent here.

Comment thread packages/octane/src/compiler/compile.js Resolved
@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 22, 2026 02:05 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 22, 2026 02:06 Inactive

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Dirty hydrate filename reaches analysis
    • Compiler-facing parse and semantic analysis now consistently strip query and hash suffixes, with regression coverage for hydrate child diagnostics.

Create PR

Or push these changes by commenting:

@cursor push 415752ab55
Preview (415752ab55)
diff --git a/packages/octane/src/compiler/compile.js b/packages/octane/src/compiler/compile.js
--- a/packages/octane/src/compiler/compile.js
+++ b/packages/octane/src/compiler/compile.js
@@ -4296,13 +4296,23 @@
 	return { result, hydrateSource: metadata.hydrateSource };
 }
 
+function cleanCompilerFilename(filename) {
+	const query = filename.indexOf('?');
+	const hash = filename.indexOf('#');
+	let filenameEnd = filename.length;
+	if (query !== -1) filenameEnd = query;
+	if (hash !== -1 && hash < filenameEnd) filenameEnd = hash;
+	return filename.slice(0, filenameEnd);
+}
+
 function compileAuthored(source, filename, options, bundlerMetadata) {
 	const mode = (options && options.mode) || 'client';
 	if (mode !== 'client' && mode !== 'server') {
 		throw new Error(`Unknown compile mode "${mode}" — expected 'client' or 'server'.`);
 	}
-	const analyzedAst = parseModule(source, filename);
-	analyzeTsrx(analyzedAst, filename);
+	const cleanFilename = cleanCompilerFilename(filename);
+	const analyzedAst = parseModule(source, cleanFilename);
+	analyzeTsrx(analyzedAst, cleanFilename);
 	return compileInternal(source, filename, options, analyzedAst, mode, bundlerMetadata);
 }
 
@@ -4313,12 +4323,7 @@
 		assertUniversalRuntimeTarget(universalRuntime, mode, options?.renderer);
 	}
 	if (!options?.__hydratePrepared) {
-		const query = filename.indexOf('?');
-		const hash = filename.indexOf('#');
-		let filenameEnd = filename.length;
-		if (query !== -1) filenameEnd = query;
-		if (hash !== -1 && hash < filenameEnd) filenameEnd = hash;
-		const cleanFilename = filename.slice(0, filenameEnd);
+		const cleanFilename = cleanCompilerFilename(filename);
 		const hydratePreparation =
 			mode === 'client'
 				? prepareHydrateBoundaries(source, cleanFilename, hydrateBoundaryPathFromId(filename))

diff --git a/packages/octane/tests/hydrate-compiler.test.ts b/packages/octane/tests/hydrate-compiler.test.ts
--- a/packages/octane/tests/hydrate-compiler.test.ts
+++ b/packages/octane/tests/hydrate-compiler.test.ts
@@ -478,6 +478,26 @@
 		expect(server.code).not.toContain('data-fallback');
 	});
 
+	it('reports split-child analysis errors against the authored filename', () => {
+		const source = `
+import { Hydrate } from 'octane';
+export function App(props) @{
+  if (props.invalid) { <span /> }
+  <Hydrate when={gate}><aside>deferred</aside></Hydrate>
+}
+`;
+		let thrown: any = null;
+		try {
+			compiler().transform(source, `${FILE}?octane-hydrate=0`, { environment: 'client' });
+		} catch (error) {
+			thrown = error;
+		}
+		expect(thrown).toMatchObject({
+			code: 'tsrx-forgotten-statement-container',
+			fileName: '/src/App.tsrx',
+		});
+	});
+
 	it('keeps composed child expression mappings anchored to authored source', () => {
 		const source = `
 import { Hydrate } from 'octane';

You can send follow-ups to the cloud agent here.

Comment thread packages/octane/src/compiler/compile.js Resolved
@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 22, 2026 02:14 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 22, 2026 02:15 Inactive

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Hash aliases truncated before analysis
    • Updated compile filename cleaning to preserve a leading Node package-import alias and added regression coverage for authored diagnostic filenames.

Create PR

Or push these changes by commenting:

@cursor push 2019dccf9d
Preview (2019dccf9d)
diff --git a/.changeset/preserve-hash-aliases.md b/.changeset/preserve-hash-aliases.md
new file mode 100644
--- /dev/null
+++ b/.changeset/preserve-hash-aliases.md
@@ -1,0 +1,5 @@
+---
+'octane': patch
+---
+
+Preserve leading Node package-import aliases in compiler analysis filenames.

diff --git a/packages/octane/src/compiler/compile.js b/packages/octane/src/compiler/compile.js
--- a/packages/octane/src/compiler/compile.js
+++ b/packages/octane/src/compiler/compile.js
@@ -4285,7 +4285,7 @@
 
 function cleanCompileFilename(filename) {
 	const query = filename.indexOf('?');
-	const hash = filename.indexOf('#');
+	const hash = filename.indexOf('#', filename.startsWith('#') ? 1 : 0);
 	let end = filename.length;
 	if (query !== -1) end = query;
 	if (hash !== -1 && hash < end) end = hash;

diff --git a/packages/octane/tests/bundler-compiler.test.ts b/packages/octane/tests/bundler-compiler.test.ts
--- a/packages/octane/tests/bundler-compiler.test.ts
+++ b/packages/octane/tests/bundler-compiler.test.ts
@@ -91,6 +91,20 @@
 		expect(canonicalModuleId('#nitro/virtual/polyfills', root)).toBe('#nitro/virtual/polyfills');
 	});
 
+	it('preserves package-import aliases in authored diagnostics', () => {
+		const compiler = createOctaneCompiler({ root: '/project' });
+		let thrown: unknown;
+		try {
+			compiler.transform(
+				'export function Button() { <button>unused</button>; return null; }',
+				'#components/Button.tsrx?octane-hydrate=0',
+			);
+		} catch (error) {
+			thrown = error;
+		}
+		expect(thrown).toMatchObject({ fileName: '#components/Button.tsrx' });
+	});
+
 	it('compiles the same source for client and server with maps', () => {
 		const compiler = createOctaneCompiler({ root: '/project' });
 		const client = compiler.transform(COMPONENT, '/project/src/App.tsrx?v=1', {

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 1d89c8a. Configure here.

Comment thread packages/octane/src/compiler/compile.js Resolved
@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 22, 2026 02:25 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 22, 2026 02:26 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 22, 2026 02:48 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 22, 2026 02:49 Inactive
@leonidaz
leonidaz requested a review from trueadm July 22, 2026 02:58
@trueadm
trueadm merged commit af337d0 into main Jul 22, 2026
22 checks passed
@trueadm
trueadm deleted the analyze branch July 22, 2026 09:12
mrdiyorbek-juraev added a commit to mrdiyorbek-juraev/octane that referenced this pull request Jul 22, 2026
Brings in 12 upstream commits, including the shared TSRX semantic analysis
across client/server/universal/Volar compilation (octanejs#230), the deferred
hydration fix (octanejs#229), Lynx Milestone 7 worklets (octanejs#227), template-free
production hydration (octanejs#218), and the dependency/TSRX toolchain refresh
(octanejs#223) with the release that followed it.

Two conflicts, both in generated files, resolved by taking upstream and
regenerating from the merged tree:

- docs/packages.md — 47 publishable packages upstream, 48 here. Verified
  as a strict superset: every package upstream lists is still present,
  and the only additions are `@octanejs/cmdk` and `packages/cmdk`.
- packages/octane-evals/.../manifest.jsonl — all 19 task ids match
  upstream, and a field-level comparison shows only
  environment.overlayLockfileHash and grader.graderDigest differ. No
  prompt, policy, reference or grader command changed, so task semantics
  are untouched; both fields derive from the lockfile, which necessarily
  moved.

pnpm install also rewrote pnpm-workspace.yaml as a side effect — it
flattened upstream's `*esrap_common` YAML anchor and appended
[email protected] to minimumReleaseAgeExclude. Both are reverted, so the file
differs from upstream by exactly one line: the `cmdk: 1.1.1` catalog pin
this package needs.

packages/cmdk is unchanged apart from one comparator re-wrapped by the
refreshed prettier; the whitespace-only diff is the entire delta.

Verified: 43/43 cmdk and cmdk-ssr against the new compiler, 48/48 evals
(including the corpus freshness gate), tsrx-tsc, tsgo, prettier, and all
five generated-artifact gates current.

This branch was previously deployed

2 inactive deployments
Preview – octane-website — 4284561b Deployed Jul 22, 2026 by vercel[bot]
Preview – octane-website-mcp — 4284561b Deployed Jul 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants