Skip to content

Commit a715164

Browse files
feat: W-21111977 consume error-page template from @salesforce/webapp-experimental/proxy
Update plugin-webapp to import the error page HTML template from the @salesforce/webapp-experimental proxy package (v1.23.0) instead of bundling it locally. Migration changes: - ErrorPageRenderer now uses getErrorPageTemplate() from @salesforce/webapp-experimental/proxy (direct import, no workarounds) - Removed local error-page.html template (now lives in webapps package) - Removed scripts/copy-templates.cjs (no longer needed) - Removed postbuild script from package.json - Bumped @salesforce/webapp-experimental dependency to ^1.23.0 Bug fixes included: - DevServerManager: emit DevServerError directly instead of wrapping in SfError, so the proxy can display the "Dev Server Error" page when dev server crashes - ProxyServer: add socket error handler to prevent ECONNRESET from crashing the proxy when dev server dies mid-connection - ProxyServer: remove label/version from fallback manifest (not in type) Depends on: salesforce-experience-platform-emu/webapps#86 (merged) Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 8220f06 commit a715164

4 files changed

Lines changed: 21 additions & 72 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@salesforce/core": "^8.25.0",
1111
"@salesforce/kit": "^3.2.4",
1212
"@salesforce/sf-plugins-core": "^12.2.6",
13-
"@salesforce/webapp-experimental": "^0.2.0",
13+
"@salesforce/webapp-experimental": "^1.23.0",
1414
"chokidar": "^3.6.0",
1515
"http-proxy": "^1.18.1",
1616
"micromatch": "^4.0.8",

src/proxy/ProxyServer.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,6 @@ export class ProxyServer extends EventEmitter {
412412
private initializeProxyHandler(): void {
413413
const manifest: WebAppManifest = this.config.manifest ?? {
414414
name: 'webapp',
415-
label: 'WebApp',
416-
version: '1.0.0',
417415
outputDir: 'dist',
418416
};
419417

src/templates/ErrorPageRenderer.ts

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

17-
// Use namespace import to avoid TS2305 when getErrorPageTemplate is not yet
18-
// available in the published version. The function is added by the W-21111977
19-
// migration in @salesforce/webapp-experimental. Once a version that includes
20-
// it is published, the runtime check below will pick it up automatically.
21-
import * as proxyExports from '@salesforce/webapp-experimental/proxy';
17+
import { getErrorPageTemplate } from '@salesforce/webapp-experimental/proxy';
2218
import type { DevServerError } from '../config/types.js';
2319

24-
/**
25-
* Load the error page template from @salesforce/webapp-experimental/proxy.
26-
* Returns null when the installed version does not yet export the function.
27-
*/
28-
function loadProxyTemplate(): string | null {
29-
try {
30-
const mod = proxyExports as unknown as Record<string, unknown>;
31-
const fn = mod['getErrorPageTemplate'];
32-
if (typeof fn === 'function') {
33-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
34-
const result = fn();
35-
if (typeof result === 'string') return result;
36-
}
37-
} catch {
38-
// Function not available in the installed version
39-
}
40-
return null;
41-
}
42-
4320
export type ErrorPageData = {
4421
status: string;
4522
devServerUrl: string;
@@ -58,46 +35,7 @@ export class ErrorPageRenderer {
5835
private template: string;
5936

6037
public constructor() {
61-
this.template = loadProxyTemplate() ?? ErrorPageRenderer.getMinimalFallbackTemplate();
62-
}
63-
64-
/**
65-
* Minimal fallback template used when the main template file cannot be loaded.
66-
* This ensures the proxy can still display error pages even if the template is missing.
67-
*/
68-
private static getMinimalFallbackTemplate(): string {
69-
return `<!DOCTYPE html>
70-
<html lang="en">
71-
<head>
72-
<meta charset="UTF-8">
73-
<title>{{PAGE_TITLE}}</title>
74-
{{META_REFRESH}}
75-
<style>
76-
body { font-family: system-ui, sans-serif; background: #1a1a2e; color: #eee; padding: 40px; }
77-
.container { max-width: 800px; margin: 0 auto; }
78-
h1 { color: #ff6b6b; }
79-
.status { color: #ffd93d; margin-bottom: 20px; }
80-
.info { background: #16213e; padding: 20px; border-radius: 8px; margin: 20px 0; }
81-
.info p { margin: 8px 0; }
82-
code { background: #0f3460; padding: 2px 6px; border-radius: 4px; }
83-
</style>
84-
</head>
85-
<body>
86-
<div class="container">
87-
<h1>{{ERROR_TITLE}}</h1>
88-
<p class="status">{{ERROR_STATUS}}</p>
89-
<div class="info">
90-
{{MESSAGE_CONTENT}}
91-
<p><strong>Dev Server:</strong> <code>{{DEV_SERVER_URL}}</code></p>
92-
<p><strong>Proxy:</strong> <code>{{PROXY_URL}}</code> (port {{PROXY_PORT}})</p>
93-
<p><strong>Org:</strong> <code>{{ORG_TARGET}}</code></p>
94-
<p><strong>Script:</strong> <code>{{WORKSPACE_SCRIPT}}</code></p>
95-
<p><strong>Last Check:</strong> {{LAST_CHECK_TIME}}</p>
96-
</div>
97-
<p style="color:#888;font-size:14px;" class="{{AUTO_REFRESH_CLASS}}">{{AUTO_REFRESH_TEXT}}</p>
98-
</div>
99-
</body>
100-
</html>`;
38+
this.template = getErrorPageTemplate();
10139
}
10240

10341
/**

yarn.lock

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,19 @@
17581758
resolved "https://registry.npmjs.org/@salesforce/prettier-config/-/prettier-config-0.0.3.tgz"
17591759
integrity sha512-hYOhoPTCSYMDYn+U1rlEk16PoBeAJPkrdg4/UtAzupM1mRRJOwEPMG1d7U8DxJFKuXW3DMEYWr2MwAIBDaHmFg==
17601760

1761+
"@salesforce/sdk-core@^1.22.0":
1762+
version "1.22.0"
1763+
resolved "https://registry.yarnpkg.com/@salesforce/sdk-core/-/sdk-core-1.22.0.tgz#6488c2a64954ef554253f7d6293239d3e3ba9e61"
1764+
integrity sha512-L3GT267pg8iRJFXLUg+DVjn76UgJSwexXhWsAV5WDiLEkXlEwKdGFmpmKYbDx9M9sUN3NckiYw+trWGRjUEHNw==
1765+
1766+
"@salesforce/sdk-data@^1.22.0":
1767+
version "1.22.0"
1768+
resolved "https://registry.yarnpkg.com/@salesforce/sdk-data/-/sdk-data-1.22.0.tgz#2dbf26f8b29f4bcc56aaf070baa74dbe64d02cd6"
1769+
integrity sha512-KH5RcQfyXj0jjvpI7gv54+e7qhiOBZ+XjuBA6UsOuk4bRvRfvqtwxCl1qSTLTU6iEoburudq6ixu1n7A6MOG+g==
1770+
dependencies:
1771+
"@conduit-client/salesforce-lightning-service-worker" "^3.7.0"
1772+
"@salesforce/sdk-core" "^1.22.0"
1773+
17611774
"@salesforce/sf-plugins-core@^11.3.12":
17621775
version "11.3.12"
17631776
resolved "https://registry.npmjs.org/@salesforce/sf-plugins-core/-/sf-plugins-core-11.3.12.tgz"
@@ -1797,13 +1810,13 @@
17971810
resolved "https://registry.npmjs.org/@salesforce/ts-types/-/ts-types-2.0.12.tgz"
17981811
integrity sha512-BIJyduJC18Kc8z+arUm5AZ9VkPRyw1KKAm+Tk+9LT99eOzhNilyfKzhZ4t+tG2lIGgnJpmytZfVDZ0e2kFul8g==
17991812

1800-
"@salesforce/webapp-experimental@^0.2.0":
1801-
version "0.2.0"
1802-
resolved "https://registry.npmjs.org/@salesforce/webapp-experimental/-/webapp-experimental-0.2.0.tgz"
1803-
integrity sha512-+E7b8u88ABJcgj7YSYiwXaF+LY9lCElibtEQbfuBdDXSUXjaMImwdZjhuyUtndIYWSXM+X38kjnIAFiikjqBIQ==
1813+
"@salesforce/webapp-experimental@^1.23.0":
1814+
version "1.23.0"
1815+
resolved "https://registry.yarnpkg.com/@salesforce/webapp-experimental/-/webapp-experimental-1.23.0.tgz#b95ebfebd3254361732e8edcfbdc56a8b819a948"
1816+
integrity sha512-5EKzZ6MFnCzmKdHSSt+28riAIgFQ+5PfPRQg3Gl0mnUA3GzN9XwzEq8hI/r52sDlKPvtb2x+MKAxyYs/182OEg==
18041817
dependencies:
1805-
"@conduit-client/salesforce-lightning-service-worker" "^3.7.0"
18061818
"@salesforce/core" "^8.23.4"
1819+
"@salesforce/sdk-data" "^1.22.0"
18071820
axios "^1.7.7"
18081821
micromatch "^4.0.8"
18091822
path-to-regexp "^8.3.0"

0 commit comments

Comments
 (0)