fix(web): change component keys to use id tied to controller lifecycle instead of item id (#1681)

* fix(web): change component keys to use id tied to controller lifecycle instead of item id

* chore: lint
This commit is contained in:
Mo
2022-09-29 10:58:10 -05:00
committed by GitHub
parent 88f35b39fb
commit 492c9bacbf
4 changed files with 11 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ import { ItemViewControllerInterface } from './ItemViewControllerInterface'
export class FileViewController implements ItemViewControllerInterface { export class FileViewController implements ItemViewControllerInterface {
public dealloced = false public dealloced = false
private removeStreamObserver?: () => void private removeStreamObserver?: () => void
public runtimeId = `${Math.random()}`
constructor(private application: SNApplication, public item: FileItem) {} constructor(private application: SNApplication, public item: FileItem) {}

View File

@@ -35,6 +35,7 @@ export class NoteViewController implements ItemViewControllerInterface {
private saveTimeout?: ReturnType<typeof setTimeout> private saveTimeout?: ReturnType<typeof setTimeout>
private defaultTitle: string | undefined private defaultTitle: string | undefined
private defaultTag: UuidString | undefined private defaultTag: UuidString | undefined
public runtimeId = `${Math.random()}`
constructor( constructor(
private application: SNApplication, private application: SNApplication,

View File

@@ -122,10 +122,10 @@ class NoteGroupView extends PureComponent<Props, State> {
<> <>
{this.state.controllers.map((controller) => { {this.state.controllers.map((controller) => {
return controller instanceof NoteViewController ? ( return controller instanceof NoteViewController ? (
<NoteView key={controller.item.uuid} application={this.application} controller={controller} /> <NoteView key={controller.runtimeId} application={this.application} controller={controller} />
) : ( ) : (
<FileView <FileView
key={controller.item.uuid} key={controller.runtimeId}
application={this.application} application={this.application}
viewControllerManager={this.viewControllerManager} viewControllerManager={this.viewControllerManager}
file={controller.item} file={controller.item}

View File

@@ -149,6 +149,9 @@ class NoteView extends PureComponent<NoteViewProps, State> {
} }
override deinit() { override deinit() {
super.deinit()
;(this.controller as unknown) = undefined
window.removeEventListener('scroll', this.handleWindowScroll) window.removeEventListener('scroll', this.handleWindowScroll)
this.removeComponentStreamObserver?.() this.removeComponentStreamObserver?.()
@@ -165,7 +168,6 @@ class NoteView extends PureComponent<NoteViewProps, State> {
this.clearNoteProtectionInactivityTimer() this.clearNoteProtectionInactivityTimer()
;(this.ensureNoteIsInsertedBeforeUIAction as unknown) = undefined ;(this.ensureNoteIsInsertedBeforeUIAction as unknown) = undefined
;(this.controller as unknown) = undefined
this.removeTabObserver?.() this.removeTabObserver?.()
this.removeTabObserver = undefined this.removeTabObserver = undefined
@@ -173,7 +175,6 @@ class NoteView extends PureComponent<NoteViewProps, State> {
this.statusTimeout = undefined this.statusTimeout = undefined
;(this.onPanelResizeFinish as unknown) = undefined ;(this.onPanelResizeFinish as unknown) = undefined
super.deinit()
;(this.dismissProtectedWarning as unknown) = undefined ;(this.dismissProtectedWarning as unknown) = undefined
;(this.editorComponentViewerRequestsReload as unknown) = undefined ;(this.editorComponentViewerRequestsReload as unknown) = undefined
;(this.onTextAreaChange as unknown) = undefined ;(this.onTextAreaChange as unknown) = undefined
@@ -313,6 +314,10 @@ class NoteView extends PureComponent<NoteViewProps, State> {
} }
override async onAppEvent(eventName: ApplicationEvent) { override async onAppEvent(eventName: ApplicationEvent) {
if (this.controller?.dealloced) {
return
}
switch (eventName) { switch (eventName) {
case ApplicationEvent.PreferencesChanged: case ApplicationEvent.PreferencesChanged:
this.reloadPreferences().catch(console.error) this.reloadPreferences().catch(console.error)