Skip to content

Commit da933f2

Browse files
committed
fix: fire event only when loaded in AEM editor
1 parent 0556b0c commit da933f2

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/Constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class Constants {
4545
/**
4646
* Event which indicates that content of remote component has been fetched and loaded in the app
4747
*/
48-
public static readonly REMOTE_CONTENT_LOADED = 'cq-remotecontent-loaded';
48+
public static readonly REMOTE_CONTENT_LOADED_EVENT = 'cq-remotecontent-loaded';
4949

5050
/**
5151
* Selector for WCM mode state meta property.

src/components/ModelProvider.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ export class ModelProvider extends Component<ModelProviderType> {
9191
this.setState(props);
9292

9393
// Fire event once component model has been fetched and rendered to enable editing on AEM
94-
if (injectPropsOnInit) {
95-
PathUtils.dispatchGlobalCustomEvent(Constants.REMOTE_CONTENT_LOADED, {});
94+
if (injectPropsOnInit && Utils.isInEditor()) {
95+
PathUtils.dispatchGlobalCustomEvent(Constants.REMOTE_CONTENT_LOADED_EVENT, {});
9696
}
9797
}
9898
}).catch((error) => {

test/ModelProvider.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ describe('ModelProvider ->', () => {
169169
expect(childNode).toBeDefined();
170170

171171
await waitFor(() =>
172-
expect(dispatchEventSpy).toHaveBeenCalledWith(Constants.REMOTE_CONTENT_LOADED, {})
172+
expect(dispatchEventSpy).toHaveBeenCalledWith(Constants.REMOTE_CONTENT_LOADED_EVENT, {})
173173
);
174174
});
175175

0 commit comments

Comments
 (0)