Skip to content

Commit 415752a

Browse files
committed
Fix hydrate analysis filenames
1 parent b8a5e3b commit 415752a

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

‎packages/octane/src/compiler/compile.js‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4296,13 +4296,23 @@ export function compileForBundler(source, filename, options) {
42964296
return { result, hydrateSource: metadata.hydrateSource };
42974297
}
42984298

4299+
function cleanCompilerFilename(filename) {
4300+
const query = filename.indexOf('?');
4301+
const hash = filename.indexOf('#');
4302+
let filenameEnd = filename.length;
4303+
if (query !== -1) filenameEnd = query;
4304+
if (hash !== -1 && hash < filenameEnd) filenameEnd = hash;
4305+
return filename.slice(0, filenameEnd);
4306+
}
4307+
42994308
function compileAuthored(source, filename, options, bundlerMetadata) {
43004309
const mode = (options && options.mode) || 'client';
43014310
if (mode !== 'client' && mode !== 'server') {
43024311
throw new Error(`Unknown compile mode "${mode}" — expected 'client' or 'server'.`);
43034312
}
4304-
const analyzedAst = parseModule(source, filename);
4305-
analyzeTsrx(analyzedAst, filename);
4313+
const cleanFilename = cleanCompilerFilename(filename);
4314+
const analyzedAst = parseModule(source, cleanFilename);
4315+
analyzeTsrx(analyzedAst, cleanFilename);
43064316
return compileInternal(source, filename, options, analyzedAst, mode, bundlerMetadata);
43074317
}
43084318

@@ -4313,12 +4323,7 @@ function compileInternal(source, filename, options, analyzedAst, mode, bundlerMe
43134323
assertUniversalRuntimeTarget(universalRuntime, mode, options?.renderer);
43144324
}
43154325
if (!options?.__hydratePrepared) {
4316-
const query = filename.indexOf('?');
4317-
const hash = filename.indexOf('#');
4318-
let filenameEnd = filename.length;
4319-
if (query !== -1) filenameEnd = query;
4320-
if (hash !== -1 && hash < filenameEnd) filenameEnd = hash;
4321-
const cleanFilename = filename.slice(0, filenameEnd);
4326+
const cleanFilename = cleanCompilerFilename(filename);
43224327
const hydratePreparation =
43234328
mode === 'client'
43244329
? prepareHydrateBoundaries(source, cleanFilename, hydrateBoundaryPathFromId(filename))

‎packages/octane/tests/hydrate-compiler.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,26 @@ export function App(props) @{
478478
expect(server.code).not.toContain('data-fallback');
479479
});
480480

481+
it('reports split-child analysis errors against the authored filename', () => {
482+
const source = `
483+
import { Hydrate } from 'octane';
484+
export function App(props) @{
485+
if (props.invalid) { <span /> }
486+
<Hydrate when={gate}><aside>deferred</aside></Hydrate>
487+
}
488+
`;
489+
let thrown: any = null;
490+
try {
491+
compiler().transform(source, `${FILE}?octane-hydrate=0`, { environment: 'client' });
492+
} catch (error) {
493+
thrown = error;
494+
}
495+
expect(thrown).toMatchObject({
496+
code: 'tsrx-forgotten-statement-container',
497+
fileName: '/src/App.tsrx',
498+
});
499+
});
500+
481501
it('keeps composed child expression mappings anchored to authored source', () => {
482502
const source = `
483503
import { Hydrate } from 'octane';

0 commit comments

Comments
 (0)