Skip to content

Commit 2a9f6e9

Browse files
committed
wip(studio): the console's /studio route pattern stays a literal; the guard spares Route path patterns (#36895)
A route pattern declares what the console serves and builds no link. The console route table is read as source text by the onSuccess navigate-host pin, whose control reads every top-level path="/..." literal; spelling the pattern through STUDIO_ROOT_PATH took 'studio' out of that table. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzhpykmQZe1yMupC2CU
1 parent 6b908b2 commit 2a9f6e9

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎ui/apps/console/src/components/StudioRoute.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import {
4949
STUDIO_METADATA_AREA,
5050
STUDIO_ORG_SCOPE_PILLAR,
5151
STUDIO_ORG_SCOPE_SEGMENT,
52-
STUDIO_ROOT_PATH,
5352
studioMetadataAreaPath,
5453
studioPackagePath,
5554
useHomePath,
@@ -334,7 +333,7 @@ function StudioPackageBuilder({ area }: { area?: typeof STUDIO_METADATA_AREA })
334333
* pillar builder as a package id.
335334
*/
336335
export const studioRoutes = (
337-
<Route path={STUDIO_ROOT_PATH} element={<StudioRoute />}>
336+
<Route path="/studio" element={<StudioRoute />}>
338337
<Route index element={<StudioLanding />} />
339338
<Route
340339
path={STUDIO_ORG_SCOPE_SEGMENT}

‎ui/packages/app-shell/src/views/studio-design/studioAddress.guard.test.ts‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
* - a path composed onto the root constant (`` `${STUDIO_ROOT_PATH}/…` ``,
1919
* `STUDIO_ROOT_PATH + '/…'`), the same hand-build one step removed.
2020
*
21+
* A route PATTERN is not an address: `<Route path="/studio">` declares what
22+
* the console serves, and builds no link. It stays a plain literal, because
23+
* the console's route table is read as source text
24+
* (`useConsoleActionRuntime.onSuccessNavigateHost-13379.test.tsx` reads every
25+
* top-level `path="/…"`), so the string initializer of a `<Route>`'s `path`
26+
* attribute is spared. Every other spelling, including a `<Link to="/studio">`
27+
* or a `path` on anything but a `<Route>`, is refused.
28+
*
2129
* `studioAddress.ts` is the one file allowed to spell the root (and the
2230
* mapping table beside it, which spells shapes, not links). The server's
2331
* two review links are held by the same kind of pin in `@objectstack/types`
@@ -93,8 +101,17 @@ function handBuiltStudioAddresses(fileName: string, text: string): string[] {
93101
hits.push(`${line + 1}: ${node.getText(source).replace(/\s+/g, ' ').slice(0, 120)}`);
94102
};
95103
const isRoot = (node: ts.Node) => ts.isIdentifier(node) && ROOT_NAMES.has(node.text);
104+
// `<Route path="/studio">`: a route pattern the console serves, not a link.
105+
const isRoutePattern = (node: ts.Node) =>
106+
ts.isStringLiteral(node) &&
107+
ts.isJsxAttribute(node.parent) &&
108+
node.parent.name.getText(source) === 'path' &&
109+
ts.isJsxAttributes(node.parent.parent) &&
110+
node.parent.parent.parent.tagName.getText(source) === 'Route';
96111
const visit = (node: ts.Node): void => {
97-
if ((ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) && STUDIO_LITERAL.test(node.text)) {
112+
if (isRoutePattern(node)) {
113+
// Spared: see the header.
114+
} else if ((ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) && STUDIO_LITERAL.test(node.text)) {
98115
hit(node);
99116
} else if (ts.isTemplateExpression(node)) {
100117
if (STUDIO_LITERAL.test(node.head.text) || (node.head.text === '' && isRoot(node.templateSpans[0].expression))) {
@@ -115,7 +132,9 @@ describe('no Studio address is built by hand under ui/ (objectstack#36895)', ()
115132
expect(scan("const a = '/studio';")).toHaveLength(1);
116133
expect(scan('const b = `/studio/${pkg}/data`;')).toHaveLength(1);
117134
expect(scan('const c = "/studio?new=package";')).toHaveLength(1);
118-
expect(scan('const d = <Route path="/studio" />;')).toHaveLength(1);
135+
expect(scan('const d = <Link to="/studio" />;')).toHaveLength(1);
136+
expect(scan('const d2 = <Tab path="/studio" />;')).toHaveLength(1);
137+
expect(scan('const d3 = <Route path={`/studio/${pkg}`} />;')).toHaveLength(1);
119138
expect(scan('const e = `${STUDIO_ROOT_PATH}/${pkg}`;')).toHaveLength(1);
120139
expect(scan("const f = STUDIO_ROOT_PATH + '/' + pkg;")).toHaveLength(1);
121140
// Not an address.
@@ -124,6 +143,9 @@ describe('no Studio address is built by hand under ui/ (objectstack#36895)', ()
124143
expect(scan("const i = 'studio:builder';")).toEqual([]);
125144
expect(scan('// opens /studio/crm/data\nconst j = 1;')).toEqual([]);
126145
expect(scan('/** `/studio/<package>/metadata` */\nconst k = 1;')).toEqual([]);
146+
// A route pattern is a declaration, not a link.
147+
expect(scan('const m = <Route path="/studio" element={<X />} />;')).toEqual([]);
148+
expect(scan('const n = <Route path="/studio/:packageId"><Route index /></Route>;')).toEqual([]);
127149
// The builder's output is not a literal.
128150
expect(scan('const l = studioHomePath(pkg);')).toEqual([]);
129151
});

0 commit comments

Comments
 (0)