{"record":{"id":"b0633aacc2b976b8","repo":"toeverything/AFFiNE","slug":"databaseblockerror-b0633a","errorCode":"DatabaseBlockError","errorMessage":"View ${viewId} not found","messagePattern":"View (.+?) not found","errorType":"exception","errorClass":"BlockSuiteError","httpStatus":null,"severity":"error","filePath":"blocksuite/affine/data-view/src/core/data-view.ts","lineNumber":67,"sourceCode":"      data: {\n        view: SingleView;\n        rowId: string;\n      }\n    ) => Promise<void>;\n  };\n};\n\nexport class DataViewRootUILogic {\n  private get dataSource() {\n    return this.config.dataSource;\n  }\n  private get viewManager() {\n    return this.dataSource.viewManager;\n  }\n  private createDataViewUILogic(viewId: string): DataViewUILogicBase {\n    const view = this.viewManager.viewGet(viewId);\n    if (!view) {\n      throw new BlockSuiteError(\n        BlockSuiteError.ErrorCode.DatabaseBlockError,\n        `View ${viewId} not found`\n      );\n    }\n\n    const pcLogic = view.meta.renderer.pcLogic;\n    const mobileLogic = view.meta.renderer.mobileLogic;\n    const logic = (IS_MOBILE ? mobileLogic : pcLogic) ?? pcLogic;\n\n    return new (logic(view))(this, view);\n  }\n  private readonly _viewsCache = new Map<\n    string,\n    { mode: string; logic: DataViewUILogicBase }\n  >();\n\n  private readonly views$ = computed(() => {\n    const viewDataList = this.dataSource.viewDataList$.value;","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/26c515e050211269e911f7d9cfe162a26c83ed98/blocksuite/affine/data-view/src/core/data-view.ts#L49-L85","documentation":"DataViewRootUILogic.createDataViewUILogic() looks up a view by id via viewManager.viewGet(viewId). If no view with that id exists in the data source it throws DatabaseBlockError. A view id is stale or refers to a view that was deleted.","triggerScenarios":"Rendering a data view with a viewId that is not present in the viewManager — e.g. a persisted selection pointing at a removed view, or a viewId passed before the view list finished loading.","commonSituations":"A user deleted a view but a stored reference (URL param, persisted state) still points to it; race between view creation and rendering; corrupted view metadata.","solutions":["Validate the viewId against viewManager.views$/viewGet() before rendering.","Fall back to a default/first view id when the requested one is missing.","Clear stale persisted selection state when a view is removed."],"exampleFix":"// before\nconst logic = root.createDataViewUILogic(missingViewId); // throws\n\n// after\nconst viewId = viewManager.viewGet(requestedId) ? requestedId : viewManager.defaultViewId;\nconst logic = root.createDataViewUILogic(viewId);","handlingStrategy":"validation","validationCode":"const view = viewManager.viewGet(viewId);\nconst safeId = view ? viewId : viewManager.views$.value[0]?.id;\nif (!safeId) throw new Error('no views available');","typeGuard":"const viewExists = (vm: any, id: string): boolean => Boolean(vm.viewGet(id));","tryCatchPattern":null,"preventionTips":["Validate viewId against the view list before rendering","Clear persisted selection when a view is deleted"],"tags":["data-view","database","view","lifecycle"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}