Skip to content

Commit 0a60f6c

Browse files
fix: consume error page from @salesforce/webapp-experimental only (W-21111977)
- ErrorPageRenderer: use getErrorPageTemplate() from package; remove local file read - Remove src/templates/error-page.html (template lives in webapps proxy package) - README: drop copy step for error-page; document package as source - resolveDevCommand/DevServerManager: generic monorepo comments Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent a48d671 commit 0a60f6c

5 files changed

Lines changed: 19 additions & 1284 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ sf plugins link .
123123
sf plugins
124124
```
125125

126+
**Build when nested in another repo (e.g. monorepo):** If `yarn build` or `npm run compile` fails with workspace name conflicts, compile manually. The error page template is consumed from `@salesforce/webapp-experimental` at runtime (W-21111977); no copy step needed.
127+
128+
```bash
129+
./node_modules/.bin/tsc -p . --pretty
130+
sf plugins link .
131+
```
132+
133+
See **[CODE_MAP.md](CODE_MAP.md)** for where AC1–AC4 and the iframe/postMessage flow live.
134+
126135
## Commands
127136

128137
### `sf webapp dev`

src/server/DevServerManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export class DevServerManager extends EventEmitter {
337337
this.logger.debug(`Starting dev server with command: ${this.options.command}`);
338338

339339
// Prefer running the dev script binary directly to avoid npm workspace resolution
340-
// (e.g. "multiple workspaces with the same name" when project is under a monorepo)
340+
// (avoids npm workspace resolution issues when project is inside a monorepo)
341341
const direct = resolveDirectDevCommand(this.options.cwd, this.options.command);
342342
const spawnOpts: SpawnOptions = {
343343
cwd: this.options.cwd,

src/server/resolveDevCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export function parseCommand(command: string): string[] {
2828

2929
/**
3030
* When command is "npm run dev" (or "yarn dev"), resolve to the webapp's dev script
31-
* binary under node_modules/.bin to avoid npm workspace resolution (e.g. VC4 monorepo
32-
* "multiple workspaces with the same name" conflict).
31+
* binary under node_modules/.bin to avoid npm workspace resolution issues when the
32+
* project lives inside a monorepo (e.g. "multiple workspaces with the same name").
3333
* Returns null to fall back to the original command.
3434
*/
3535
export function resolveDirectDevCommand(

src/templates/ErrorPageRenderer.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { readFileSync } from 'node:fs';
18-
import { dirname, join } from 'node:path';
19-
import { fileURLToPath } from 'node:url';
2017
import { getErrorPageTemplate } from '@salesforce/webapp-experimental/proxy';
2118
import type { DevServerError } from '../config/types.js';
2219

23-
const __dirname = dirname(fileURLToPath(import.meta.url));
24-
2520
export type ErrorPageData = {
2621
status: string;
2722
devServerUrl: string;
@@ -32,25 +27,19 @@ export type ErrorPageData = {
3227

3328
/**
3429
* Renders HTML error pages for browser display when dev server is unavailable
35-
* or when runtime errors occur
36-
*
37-
* Uses a single template with conditional sections for all error types
30+
* or when runtime errors occur. Template is consumed from @salesforce/webapp-experimental
31+
* (W-21111977: single source of truth in webapps proxy package).
3832
*/
3933
export class ErrorPageRenderer {
4034
private template: string;
4135

4236
public constructor() {
43-
// Prefer plugin's own template (full Quick Actions: Retry, Start npm run dev, Restart, Force Kill, Proxy-only, URL)
44-
const localPath = join(__dirname, 'error-page.html');
4537
try {
46-
this.template = readFileSync(localPath, 'utf-8');
47-
} catch {
48-
try {
49-
this.template = getErrorPageTemplate();
50-
} catch {
51-
console.warn('[ErrorPageRenderer] Using minimal fallback template.');
52-
this.template = ErrorPageRenderer.getMinimalFallbackTemplate();
53-
}
38+
this.template = getErrorPageTemplate();
39+
} catch (error) {
40+
// eslint-disable-next-line no-console
41+
console.warn('[ErrorPageRenderer] Failed to load template from package, using minimal fallback:', error);
42+
this.template = ErrorPageRenderer.getMinimalFallbackTemplate();
5443
}
5544
}
5645

0 commit comments

Comments
 (0)