fix: unmount component on destroy
This commit is contained in:
@@ -32,13 +32,13 @@ const avoidFlickerTimeout = 7;
|
|||||||
|
|
||||||
export const ComponentView: FunctionalComponent<IProps> = observer(
|
export const ComponentView: FunctionalComponent<IProps> = observer(
|
||||||
({
|
({
|
||||||
application,
|
application,
|
||||||
appState,
|
appState,
|
||||||
onLoad,
|
onLoad,
|
||||||
componentUuid,
|
componentUuid,
|
||||||
templateComponent,
|
templateComponent,
|
||||||
manualDealloc = false,
|
manualDealloc = false,
|
||||||
}) => {
|
}) => {
|
||||||
const liveComponentRef = useRef<LiveItem<SNComponent> | null>(null);
|
const liveComponentRef = useRef<LiveItem<SNComponent> | null>(null);
|
||||||
const iframeRef = useRef<HTMLIFrameElement>(null);
|
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ export const ComponentView: FunctionalComponent<IProps> = observer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const offlineRestricted = component.offlineOnly && !isDesktopApplication();
|
const offlineRestricted = component.offlineOnly && !isDesktopApplication();
|
||||||
const hasUrlError = function() {
|
const hasUrlError = function () {
|
||||||
if (isDesktopApplication()) {
|
if (isDesktopApplication()) {
|
||||||
return !component.local_url && !component.hasValidHostedUrl();
|
return !component.local_url && !component.hasValidHostedUrl();
|
||||||
} else {
|
} else {
|
||||||
@@ -121,7 +121,7 @@ export const ComponentView: FunctionalComponent<IProps> = observer(
|
|||||||
}
|
}
|
||||||
}, [isIssueOnLoading]);
|
}, [isIssueOnLoading]);
|
||||||
|
|
||||||
const handleIframeLoadTimeout =useCallback(async () => {
|
const handleIframeLoadTimeout = useCallback(async () => {
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
setIsIssueOnLoading(true);
|
setIsIssueOnLoading(true);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { FunctionComponent, h, render } from 'preact';
|
import { FunctionComponent, h, render } from 'preact';
|
||||||
|
import { unmountComponentAtNode } from 'preact/compat';
|
||||||
import { StateUpdater, useCallback, useState } from 'preact/hooks';
|
import { StateUpdater, useCallback, useState } from 'preact/hooks';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
@@ -70,6 +71,9 @@ export function toDirective<Props>(
|
|||||||
$onChanges() {
|
$onChanges() {
|
||||||
render(h(component, $scope), $element[0]);
|
render(h(component, $scope), $element[0]);
|
||||||
},
|
},
|
||||||
|
$onDestroy() {
|
||||||
|
unmountComponentAtNode($element[0]);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async reloadEditor() {
|
private async reloadEditor() {
|
||||||
const newEditor = this.application.componentManager!.editorForNote(
|
const newEditor = this.application.componentManager.editorForNote(
|
||||||
this.note
|
this.note
|
||||||
);
|
);
|
||||||
/** Editors cannot interact with template notes so the note must be inserted */
|
/** Editors cannot interact with template notes so the note must be inserted */
|
||||||
@@ -334,7 +334,7 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
|||||||
});
|
});
|
||||||
this.reloadFont();
|
this.reloadFont();
|
||||||
}
|
}
|
||||||
this.application.componentManager!.contextItemDidChangeInArea(
|
this.application.componentManager.contextItemDidChangeInArea(
|
||||||
ComponentArea.Editor
|
ComponentArea.Editor
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -718,7 +718,7 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
|||||||
|
|
||||||
registerComponentHandler() {
|
registerComponentHandler() {
|
||||||
this.unregisterComponent =
|
this.unregisterComponent =
|
||||||
this.application.componentManager!.registerHandler({
|
this.application.componentManager.registerHandler({
|
||||||
identifier: 'editor',
|
identifier: 'editor',
|
||||||
areas: [ComponentArea.EditorStack, ComponentArea.Editor],
|
areas: [ComponentArea.EditorStack, ComponentArea.Editor],
|
||||||
contextRequestHandler: (componentUuid) => {
|
contextRequestHandler: (componentUuid) => {
|
||||||
@@ -747,7 +747,7 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
|||||||
if (this.note) {
|
if (this.note) {
|
||||||
for (const component of stackComponents) {
|
for (const component of stackComponents) {
|
||||||
if (component.active) {
|
if (component.active) {
|
||||||
this.application.componentManager!.setComponentHidden(
|
this.application.componentManager.setComponentHidden(
|
||||||
component,
|
component,
|
||||||
!component.isExplicitlyEnabledForItem(this.note.uuid)
|
!component.isExplicitlyEnabledForItem(this.note.uuid)
|
||||||
);
|
);
|
||||||
@@ -755,7 +755,7 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
await this.setState({ stackComponents });
|
await this.setState({ stackComponents });
|
||||||
this.application.componentManager!.contextItemDidChangeInArea(
|
this.application.componentManager.contextItemDidChangeInArea(
|
||||||
ComponentArea.EditorStack
|
ComponentArea.EditorStack
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -766,15 +766,15 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
|||||||
|
|
||||||
async toggleStackComponentForCurrentItem(component: SNComponent) {
|
async toggleStackComponentForCurrentItem(component: SNComponent) {
|
||||||
const hidden =
|
const hidden =
|
||||||
this.application.componentManager!.isComponentHidden(component);
|
this.application.componentManager.isComponentHidden(component);
|
||||||
if (hidden || !component.active) {
|
if (hidden || !component.active) {
|
||||||
this.application.componentManager!.setComponentHidden(component, false);
|
this.application.componentManager.setComponentHidden(component, false);
|
||||||
await this.associateComponentWithCurrentNote(component);
|
await this.associateComponentWithCurrentNote(component);
|
||||||
this.application.componentManager!.contextItemDidChangeInArea(
|
this.application.componentManager.contextItemDidChangeInArea(
|
||||||
ComponentArea.EditorStack
|
ComponentArea.EditorStack
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.application.componentManager!.setComponentHidden(component, true);
|
this.application.componentManager.setComponentHidden(component, true);
|
||||||
await this.disassociateComponentWithCurrentNote(component);
|
await this.disassociateComponentWithCurrentNote(component);
|
||||||
}
|
}
|
||||||
this.application.sync();
|
this.application.sync();
|
||||||
|
|||||||
Reference in New Issue
Block a user