@salesforce/webapp-template-feature-react-agentforce-conversation-client-experimental 1.36.3 → 1.36.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.36.4](https://github.com/salesforce-experience-platform-emu/webapps/compare/v1.36.3...v1.36.4) (2026-02-19)
7
+
8
+ **Note:** Version bump only for package @salesforce/webapp-template-base-sfdx-project-experimental
9
+
10
+
11
+
12
+
13
+
6
14
  ## [1.36.3](https://github.com/salesforce-experience-platform-emu/webapps/compare/v1.36.2...v1.36.3) (2026-02-19)
7
15
 
8
16
  **Note:** Version bump only for package @salesforce/webapp-template-base-sfdx-project-experimental
@@ -8,7 +8,7 @@
8
8
  "name": "base-react-app",
9
9
  "version": "1.0.0",
10
10
  "dependencies": {
11
- "@salesforce/agentforce-conversation-client": "^1.36.2",
11
+ "@salesforce/agentforce-conversation-client": "^1.36.3",
12
12
  "@salesforce/sdk-data": "^1.11.2",
13
13
  "@salesforce/webapp-experimental": "*",
14
14
  "@tailwindcss/vite": "^4.1.17",
@@ -3486,9 +3486,9 @@
3486
3486
  ]
3487
3487
  },
3488
3488
  "node_modules/@salesforce/agentforce-conversation-client": {
3489
- "version": "1.36.2",
3490
- "resolved": "https://registry.npmjs.org/@salesforce/agentforce-conversation-client/-/agentforce-conversation-client-1.36.2.tgz",
3491
- "integrity": "sha512-P6RTHgjQpGjznC7lKNZVC/oi+QEXuWROS7mzYNfg00Y/pIfEpLCWpcMVoGCSkQToRfYiY7/pyGOxyWptiLxnGA==",
3489
+ "version": "1.36.3",
3490
+ "resolved": "https://registry.npmjs.org/@salesforce/agentforce-conversation-client/-/agentforce-conversation-client-1.36.3.tgz",
3491
+ "integrity": "sha512-F4wLqBqptRoj46QOyUXu0qcQWx4ZGgx580k04gm5D1qGJhD1zga+ZH64aWNhlfBc/mcbfNAqVytuTzbzvHo41w==",
3492
3492
  "license": "SEE LICENSE IN LICENSE.txt",
3493
3493
  "dependencies": {
3494
3494
  "@lightning-out/application": "2.1.1-rc.2"
@@ -14,7 +14,7 @@
14
14
  "graphql:schema": "node scripts/get-graphql-schema.mjs"
15
15
  },
16
16
  "dependencies": {
17
- "@salesforce/agentforce-conversation-client": "^1.36.2",
17
+ "@salesforce/agentforce-conversation-client": "^1.36.3",
18
18
  "@salesforce/sdk-data": "^1.11.2",
19
19
  "@salesforce/webapp-experimental": "*",
20
20
  "@tailwindcss/vite": "^4.1.17",
@@ -4,23 +4,46 @@
4
4
  * For full license text, see the LICENSE.txt file
5
5
  */
6
6
 
7
- import {
8
- embedAgentforceClient,
9
- type EmbedAgentforceClientResult,
10
- } from "@salesforce/agentforce-conversation-client";
11
- import { useEffect, useRef } from "react";
7
+ import { embedAgentforceClient } from "@salesforce/agentforce-conversation-client";
8
+ import { useEffect } from "react";
12
9
  import type {
13
10
  ResolvedEmbedOptions,
14
11
  AgentforceConversationClientProps,
15
12
  } from "../types/conversation";
16
13
 
17
- async function resolveEmbedOptions(): Promise<ResolvedEmbedOptions> {
18
- if (window.location.hostname === "localhost") {
19
- const res = await fetch("/__lo/frontdoor");
20
- if (!res.ok) console.error("frontdoor fetch failed");
21
- const { frontdoorUrl } = await res.json();
22
- return { frontdoorUrl: frontdoorUrl };
14
+ const GLOBAL_HOST_ID = "agentforce-conversation-client-global-host";
15
+ const SINGLETON_KEY = "__agentforceConversationClientSingleton";
16
+
17
+ interface AgentforceConversationClientSingleton {
18
+ initPromise?: Promise<void>;
19
+ initialized: boolean;
20
+ }
21
+
22
+ interface WindowWithAgentforceSingleton extends Window {
23
+ [SINGLETON_KEY]?: AgentforceConversationClientSingleton;
24
+ }
25
+
26
+ function getSingleton(): AgentforceConversationClientSingleton {
27
+ const win = window as WindowWithAgentforceSingleton;
28
+ if (!win[SINGLETON_KEY]) {
29
+ win[SINGLETON_KEY] = {
30
+ initialized: false,
31
+ };
23
32
  }
33
+ return win[SINGLETON_KEY]!;
34
+ }
35
+
36
+ function getOrCreateGlobalHost(): HTMLDivElement {
37
+ let host = document.getElementById(GLOBAL_HOST_ID) as HTMLDivElement | null;
38
+ if (!host) {
39
+ host = document.createElement("div");
40
+ host.id = GLOBAL_HOST_ID;
41
+ document.body.appendChild(host);
42
+ }
43
+ return host;
44
+ }
45
+
46
+ function getDefaultEmbedOptions(): ResolvedEmbedOptions {
24
47
  return { salesforceOrigin: window.location.origin };
25
48
  }
26
49
 
@@ -34,39 +57,71 @@ export function AgentforceConversationClient({
34
57
  salesforceOrigin,
35
58
  frontdoorUrl,
36
59
  }: AgentforceConversationClientProps) {
37
- const containerRef = useRef<HTMLDivElement>(null);
38
- const embedResultRef = useRef<EmbedAgentforceClientResult | null>(null);
39
-
40
60
  useEffect(() => {
41
- const container = containerRef.current;
42
- if (!container) return;
61
+ const singleton = getSingleton();
62
+ if (singleton.initialized || singleton.initPromise) {
63
+ return;
64
+ }
43
65
 
44
- resolveEmbedOptions().then((options) => {
45
- try {
46
- const result = embedAgentforceClient({
47
- container,
48
- salesforceOrigin: salesforceOrigin ?? options.salesforceOrigin,
49
- frontdoorUrl: frontdoorUrl ?? options.frontdoorUrl,
50
- agentforceClientConfig: agentforceClientConfig,
51
- });
52
- embedResultRef.current = result;
53
- } catch (err) {
54
- console.error("AgentforceConversationClient: failed to embed Agentforce client", err);
66
+ const initialize = (options: ResolvedEmbedOptions) => {
67
+ // If already initialized while this flow was in progress, no-op.
68
+ if (singleton.initialized) {
69
+ return;
55
70
  }
56
- });
71
+ const existingEmbed = document.querySelector('lightning-out-application[data-lo="acc"]');
72
+ if (existingEmbed) {
73
+ singleton.initialized = true;
74
+ return;
75
+ }
76
+ const host = getOrCreateGlobalHost();
77
+
78
+ embedAgentforceClient({
79
+ container: host,
80
+ salesforceOrigin: salesforceOrigin ?? options.salesforceOrigin,
81
+ frontdoorUrl: frontdoorUrl ?? options.frontdoorUrl,
82
+ agentforceClientConfig: agentforceClientConfig,
83
+ });
84
+ singleton.initialized = true;
85
+ };
86
+
87
+ const shouldFetchFrontdoor = window.location.hostname === "localhost";
88
+
89
+ if (shouldFetchFrontdoor) {
90
+ singleton.initPromise = fetch("/__lo/frontdoor")
91
+ .then(async (res) => {
92
+ if (!res.ok) {
93
+ console.error("frontdoor fetch failed");
94
+ return;
95
+ }
96
+ const { frontdoorUrl: resolvedFrontdoorUrl } = await res.json();
97
+ initialize({ frontdoorUrl: resolvedFrontdoorUrl });
98
+ })
99
+ .catch((err) => {
100
+ console.error("AgentforceConversationClient: failed to fetch frontdoor URL", err);
101
+ })
102
+ .finally(() => {
103
+ singleton.initPromise = undefined;
104
+ });
105
+ } else {
106
+ singleton.initPromise = Promise.resolve()
107
+ .then(() => {
108
+ initialize(getDefaultEmbedOptions());
109
+ })
110
+ .catch((err) => {
111
+ console.error("AgentforceConversationClient: failed to embed Agentforce client", err);
112
+ })
113
+ .finally(() => {
114
+ singleton.initPromise = undefined;
115
+ });
116
+ }
57
117
 
58
118
  return () => {
59
- embedResultRef.current = null;
119
+ // Intentionally no cleanup:
120
+ // This component guarantees a single LO initialization per window.
60
121
  };
61
122
  }, [salesforceOrigin, frontdoorUrl, agentforceClientConfig]);
62
123
 
63
- return (
64
- <div
65
- ref={containerRef}
66
- className="agentforce-conversation-client-container"
67
- id="agentforce-conversation-client-container"
68
- />
69
- );
124
+ return null;
70
125
  }
71
126
 
72
127
  export default AgentforceConversationClient;
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/webapp-template-base-sfdx-project-experimental",
3
- "version": "1.36.3",
3
+ "version": "1.36.4",
4
4
  "description": "Base SFDX project template",
5
5
  "private": true,
6
6
  "files": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/webapp-template-feature-react-agentforce-conversation-client-experimental",
3
- "version": "1.36.3",
3
+ "version": "1.36.4",
4
4
  "description": "Embedded Agentforce conversation client feature for web applications",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "",
@@ -32,7 +32,7 @@
32
32
  "watch": "npx tsx ../../cli/src/index.ts watch-patches packages/template/feature/feature-react-agentforce-conversation-client packages/template/base-app/base-react-app packages/template/feature/feature-react-agentforce-conversation-client/dist"
33
33
  },
34
34
  "dependencies": {
35
- "@salesforce/agentforce-conversation-client": "^1.36.3"
35
+ "@salesforce/agentforce-conversation-client": "^1.36.4"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/react": "^19.2.7",
@@ -51,5 +51,5 @@
51
51
  }
52
52
  }
53
53
  },
54
- "gitHead": "7eef94f53086bb08b0545f5f61d3cbfed3fe0197"
54
+ "gitHead": "369c2dfde825a4a360489f6a26955605f368d247"
55
55
  }
@@ -4,23 +4,46 @@
4
4
  * For full license text, see the LICENSE.txt file
5
5
  */
6
6
 
7
- import {
8
- embedAgentforceClient,
9
- type EmbedAgentforceClientResult,
10
- } from "@salesforce/agentforce-conversation-client";
11
- import { useEffect, useRef } from "react";
7
+ import { embedAgentforceClient } from "@salesforce/agentforce-conversation-client";
8
+ import { useEffect } from "react";
12
9
  import type {
13
10
  ResolvedEmbedOptions,
14
11
  AgentforceConversationClientProps,
15
12
  } from "../types/conversation";
16
13
 
17
- async function resolveEmbedOptions(): Promise<ResolvedEmbedOptions> {
18
- if (window.location.hostname === "localhost") {
19
- const res = await fetch("/__lo/frontdoor");
20
- if (!res.ok) console.error("frontdoor fetch failed");
21
- const { frontdoorUrl } = await res.json();
22
- return { frontdoorUrl: frontdoorUrl };
14
+ const GLOBAL_HOST_ID = "agentforce-conversation-client-global-host";
15
+ const SINGLETON_KEY = "__agentforceConversationClientSingleton";
16
+
17
+ interface AgentforceConversationClientSingleton {
18
+ initPromise?: Promise<void>;
19
+ initialized: boolean;
20
+ }
21
+
22
+ interface WindowWithAgentforceSingleton extends Window {
23
+ [SINGLETON_KEY]?: AgentforceConversationClientSingleton;
24
+ }
25
+
26
+ function getSingleton(): AgentforceConversationClientSingleton {
27
+ const win = window as WindowWithAgentforceSingleton;
28
+ if (!win[SINGLETON_KEY]) {
29
+ win[SINGLETON_KEY] = {
30
+ initialized: false,
31
+ };
23
32
  }
33
+ return win[SINGLETON_KEY]!;
34
+ }
35
+
36
+ function getOrCreateGlobalHost(): HTMLDivElement {
37
+ let host = document.getElementById(GLOBAL_HOST_ID) as HTMLDivElement | null;
38
+ if (!host) {
39
+ host = document.createElement("div");
40
+ host.id = GLOBAL_HOST_ID;
41
+ document.body.appendChild(host);
42
+ }
43
+ return host;
44
+ }
45
+
46
+ function getDefaultEmbedOptions(): ResolvedEmbedOptions {
24
47
  return { salesforceOrigin: window.location.origin };
25
48
  }
26
49
 
@@ -34,39 +57,71 @@ export function AgentforceConversationClient({
34
57
  salesforceOrigin,
35
58
  frontdoorUrl,
36
59
  }: AgentforceConversationClientProps) {
37
- const containerRef = useRef<HTMLDivElement>(null);
38
- const embedResultRef = useRef<EmbedAgentforceClientResult | null>(null);
39
-
40
60
  useEffect(() => {
41
- const container = containerRef.current;
42
- if (!container) return;
61
+ const singleton = getSingleton();
62
+ if (singleton.initialized || singleton.initPromise) {
63
+ return;
64
+ }
43
65
 
44
- resolveEmbedOptions().then((options) => {
45
- try {
46
- const result = embedAgentforceClient({
47
- container,
48
- salesforceOrigin: salesforceOrigin ?? options.salesforceOrigin,
49
- frontdoorUrl: frontdoorUrl ?? options.frontdoorUrl,
50
- agentforceClientConfig: agentforceClientConfig,
51
- });
52
- embedResultRef.current = result;
53
- } catch (err) {
54
- console.error("AgentforceConversationClient: failed to embed Agentforce client", err);
66
+ const initialize = (options: ResolvedEmbedOptions) => {
67
+ // If already initialized while this flow was in progress, no-op.
68
+ if (singleton.initialized) {
69
+ return;
55
70
  }
56
- });
71
+ const existingEmbed = document.querySelector('lightning-out-application[data-lo="acc"]');
72
+ if (existingEmbed) {
73
+ singleton.initialized = true;
74
+ return;
75
+ }
76
+ const host = getOrCreateGlobalHost();
77
+
78
+ embedAgentforceClient({
79
+ container: host,
80
+ salesforceOrigin: salesforceOrigin ?? options.salesforceOrigin,
81
+ frontdoorUrl: frontdoorUrl ?? options.frontdoorUrl,
82
+ agentforceClientConfig: agentforceClientConfig,
83
+ });
84
+ singleton.initialized = true;
85
+ };
86
+
87
+ const shouldFetchFrontdoor = window.location.hostname === "localhost";
88
+
89
+ if (shouldFetchFrontdoor) {
90
+ singleton.initPromise = fetch("/__lo/frontdoor")
91
+ .then(async (res) => {
92
+ if (!res.ok) {
93
+ console.error("frontdoor fetch failed");
94
+ return;
95
+ }
96
+ const { frontdoorUrl: resolvedFrontdoorUrl } = await res.json();
97
+ initialize({ frontdoorUrl: resolvedFrontdoorUrl });
98
+ })
99
+ .catch((err) => {
100
+ console.error("AgentforceConversationClient: failed to fetch frontdoor URL", err);
101
+ })
102
+ .finally(() => {
103
+ singleton.initPromise = undefined;
104
+ });
105
+ } else {
106
+ singleton.initPromise = Promise.resolve()
107
+ .then(() => {
108
+ initialize(getDefaultEmbedOptions());
109
+ })
110
+ .catch((err) => {
111
+ console.error("AgentforceConversationClient: failed to embed Agentforce client", err);
112
+ })
113
+ .finally(() => {
114
+ singleton.initPromise = undefined;
115
+ });
116
+ }
57
117
 
58
118
  return () => {
59
- embedResultRef.current = null;
119
+ // Intentionally no cleanup:
120
+ // This component guarantees a single LO initialization per window.
60
121
  };
61
122
  }, [salesforceOrigin, frontdoorUrl, agentforceClientConfig]);
62
123
 
63
- return (
64
- <div
65
- ref={containerRef}
66
- className="agentforce-conversation-client-container"
67
- id="agentforce-conversation-client-container"
68
- />
69
- );
124
+ return null;
70
125
  }
71
126
 
72
127
  export default AgentforceConversationClient;