fixes: editor crash on switching versions from viewer

This commit is contained in:
arpitnath 2024-04-11 11:35:18 +05:30
parent a12ca9fed8
commit 4745d0019c
2 changed files with 15 additions and 2 deletions

View file

@ -244,6 +244,8 @@ export const Container = ({
return; return;
} }
if (!appDefinition.pages[currentPageId]?.components) return;
const newDefinition = { const newDefinition = {
...appDefinition, ...appDefinition,
pages: { pages: {
@ -251,7 +253,7 @@ export const Container = ({
[currentPageId]: { [currentPageId]: {
...appDefinition.pages[currentPageId], ...appDefinition.pages[currentPageId],
components: { components: {
...appDefinition.pages[currentPageId].components, ...appDefinition.pages[currentPageId]?.components,
...boxes, ...boxes,
}, },
}, },

View file

@ -709,7 +709,18 @@ class ViewerComponent extends React.Component {
}; };
handleEvent = (eventName, events, options) => { handleEvent = (eventName, events, options) => {
return onEvent(this.getViewerRef(), eventName, events, options, 'view'); const latestEvents = useAppDataStore.getState().events;
const filteredEvents = latestEvents.filter((event) => {
const foundEvent = events.find((e) => e.id === event.id);
return foundEvent && foundEvent.name === eventName;
});
try {
return onEvent(this.getViewerRef(), eventName, filteredEvents, options, 'view');
} catch (error) {
console.error(error);
}
}; };
computeCanvasMaxWidth = () => { computeCanvasMaxWidth = () => {