Skip to content

Commit c9fb32b

Browse files
committed
improve environment initialization
1 parent 1821d62 commit c9fb32b

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/mainPage/index.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@
44
*/
55

66
import { LiveStore, NamedNode } from 'rdflib'
7+
import type { RenderEnvironment } from 'pane-registry'
78
import { getOutliner, OutlineManager } from '../index'
89
import { createHeader, refreshHeader } from './header'
910
import { createFooter } from './footer'
1011
import { createLeftSideMenu, refreshMenu } from './menu'
1112

13+
// Symbol used to stash the last render-relevant env snapshot on the outliner
14+
// so refreshUI can skip a full GotoSubject re-render when nothing changed.
15+
const LAST_RENDER_ENV_KEY = '__lastRenderEnvSignature'
16+
17+
function renderEnvSignature (env?: RenderEnvironment): string {
18+
if (!env) return ''
19+
return [env.layout, env.theme, env.inputMode].join('|')
20+
}
21+
1222
export { refreshMenu as updateMenuLayout } from './menu'
1323
export { refreshHeader } from './header'
1424

@@ -28,10 +38,11 @@ function ensureMainContent () {
2838
export async function initMainPage (
2939
store: LiveStore,
3040
uri?: string | NamedNode | null,
31-
environment?: any
41+
environment?: RenderEnvironment
3242
) {
3343
ensureMainContent()
3444
const outliner = getOutliner(document, environment)
45+
;(outliner as any)[LAST_RENDER_ENV_KEY] = renderEnvSignature(environment)
3546
uri = uri || window.location.href
3647
const subject: NamedNode = typeof uri === 'string' ? store.sym(uri) : uri
3748
outliner.GotoSubject(subject, true, undefined, true, undefined)
@@ -49,8 +60,15 @@ export async function refreshUI (outliner: OutlineManager) {
4960
const paneName = window.history.state?.paneName
5061
const pane = paneName ? paneRegistry?.byName?.(paneName) : undefined
5162

52-
if (store && typeof outliner?.GotoSubject === 'function') {
63+
// Only re-run GotoSubject (full pane re-render) when render-relevant
64+
// environment fields actually changed since the last render.
65+
const currentSignature = renderEnvSignature(outliner?.context?.environment)
66+
const previousSignature = (outliner as any)?.[LAST_RENDER_ENV_KEY] ?? ''
67+
const envChanged = currentSignature !== previousSignature
68+
69+
if (envChanged && store && typeof outliner?.GotoSubject === 'function') {
5370
outliner.GotoSubject(store.sym(subjectUri), true, pane, true, undefined)
71+
;(outliner as any)[LAST_RENDER_ENV_KEY] = currentSignature
5472
}
5573

5674
await refreshHeader(outliner)

0 commit comments

Comments
 (0)