Skip to content

Commit 182787e

Browse files
committed
fix(octane): treat namespaced hosts as stampable in hydrate style checks
The S8.5 straddle guard missed JSXNamespacedName hosts that the style-scope pass still stamps, so a parent-list scoped style with only namespaced hosts inside the split was allowed and could emit disagreeing class lists.
1 parent d27abde commit 182787e

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎packages/octane/src/compiler/hydrate-boundaries.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,9 @@ function isStampableHost(node) {
510510
if (name.type === 'JSXIdentifier' || name.type === 'Identifier') {
511511
return name.name !== 'style' && !/^[A-Z]/.test(name.name);
512512
}
513-
return false;
513+
// Namespaced hosts (`svg:rect`) are stamped by the style-scope pass;
514+
// member expressions are composites and are not.
515+
return name.type === 'JSXNamespacedName' || name.type === 'NamespacedName';
514516
}
515517

516518
function walkStampableHosts(node, visitHost) {

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,32 @@ export function App() @{
10981098
expect(thrown.message).toContain('split={false}');
10991099
});
11001100

1101+
it('rejects a style scope that straddles a split boundary through a namespaced host', () => {
1102+
// A namespaced host is stamped by the style-scope pass. If the
1103+
// straddle check missed it, a parent-list <style> would extract
1104+
// while the server still stamped the host — disagreeing class lists.
1105+
const source = `
1106+
import { Hydrate } from 'octane';
1107+
export function App() @{
1108+
<div>
1109+
<style>.x { color: red; }</style>
1110+
<Hydrate when={gate}>
1111+
<svg:rect class="x" />
1112+
</Hydrate>
1113+
</div>
1114+
}
1115+
`;
1116+
let thrown: any = null;
1117+
try {
1118+
compiler().transform(source, FILE, { environment: 'client' });
1119+
} catch (error) {
1120+
thrown = error;
1121+
}
1122+
expect(thrown).toMatchObject({ code: 'OCTANE_HYDRATE_SPLIT_STYLE', filename: '/src/App.tsrx' });
1123+
expect(thrown.message).toContain('straddle a split Hydrate boundary');
1124+
expect(thrown.message).toContain('split={false}');
1125+
});
1126+
11011127
it('permits scoped styles under split={false} and inside nested split-child functions', () => {
11021128
// split={false} keeps children in the owning component, so its style
11031129
// scope stays whole; a style nested in a function never joined that

0 commit comments

Comments
 (0)