Skip to content

Commit 8ccf564

Browse files
committed
feat: improve component preview URL generation
1 parent f8e4a2d commit 8ccf564

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/commands/lightning/dev/component.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,23 @@ export default class LightningDevComponent extends SfCommand<void> {
131131

132132
// Construct and log the full URL that will be opened
133133
const connection = targetOrg.getConnection();
134-
// Decode the path once to match what org:open actually opens
135-
const decodedPath = decodeURIComponent(launchArguments[1]);
136-
const fullUrl = `${connection.instanceUrl}/${decodedPath}`;
137-
this.log(`PreviewURL: ${fullUrl}`);
134+
135+
const decodedFullUrl = PreviewUtils.generateComponentPreviewUrl(
136+
connection.instanceUrl,
137+
ldpServerUrl,
138+
ldpServerId,
139+
componentName,
140+
false
141+
);
142+
// const encodedFullUrl = PreviewUtils.generateComponentPreviewUrl(
143+
// connection.instanceUrl,
144+
// ldpServerUrl,
145+
// ldpServerId,
146+
// componentName,
147+
// true
148+
// );
149+
this.log(`PreviewURL: ${decodedFullUrl}`);
150+
// this.log(`EncodedPreviewURL: ${encodedFullUrl}`);
138151

139152
// Open the browser and navigate to the right page (unless OPEN_BROWSER is set to true)
140153
if (process.env.OPEN_BROWSER !== 'false') {

src/shared/previewUtils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,24 @@ export class PreviewUtils {
246246
return launchArguments;
247247
}
248248

249+
public static generateComponentPreviewUrl(
250+
instanceUrl: string,
251+
ldpServerUrl: string,
252+
ldpServerId: string,
253+
componentName?: string,
254+
encodePath = false
255+
): string {
256+
let url = `${instanceUrl}/lwr/application/e/devpreview/ai/${
257+
encodePath ? encodeURIComponent('localdev%2Fpreview') : 'localdev%2Fpreview'
258+
}?ldpServerUrl=${ldpServerUrl}&ldpServerId=${ldpServerId}`;
259+
if (componentName) {
260+
// TODO: support other namespaces
261+
url += `&specifier=c/${componentName}`;
262+
}
263+
264+
return url;
265+
}
266+
249267
/**
250268
* Generates the proper set of arguments to be used for launching a mobile app with custom launch arguments.
251269
*

0 commit comments

Comments
 (0)