Skip to content

Commit 5c259cb

Browse files
authored
Avoid duplicate renders; set project-id on load (#468)
* Avoid duplicate renders; set project-id on load Track the current manifest ID in ProjectDetails and skip render() when the manifest hasn't changed to prevent duplicate/expensive re-renders (components/project-details/index.js). Also add a render() helper and set the tpen-project-id attribute on tpen-project-details when the tpen-project-loaded event fires so the component receives the project ID and performs a controlled render (interfaces/project/index.html). * Use manifest JSON key to avoid redundant renders Change render guard to use a JSON string key of project.manifest to detect content changes and prevent duplicate renders. Rename _currentManifestId to _currentManifestKey and update the comparison to use JSON.stringify(project?.manifest ?? []) in components/project-details/index.js. In interfaces/project/index.html, rename render() to setProjectId() and call it on tpen-project-loaded to clarify intent. Includes minor whitespace cleanup. * Reset manifest key; rename render function Clear _currentManifestKey during component cleanup to avoid retaining stale manifest state. Also rename the top-level render() function in manage-project to applyProjectContext() and update its invocation to better reflect that it applies project context with permission checks. * this is the actual fix for the PR * Is this key tidier? * testing canvas-panel * Revert "testing canvas-panel" This reverts commit 39591e1.
1 parent fb6e8c5 commit 5c259cb

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

components/project-details/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class ProjectDetails extends HTMLElement {
1717
renderCleanup = new CleanupRegistry()
1818
/** @type {Function|null} Unsubscribe function for project ready listener */
1919
_unsubProject = null
20+
/** @type {string|null} Track manifest key to prevent duplicate renders */
21+
_currentManifestKey = null
2022

2123
style = `
2224
sequence-panel {
@@ -125,10 +127,26 @@ class ProjectDetails extends HTMLElement {
125127
try { this._unsubProject?.() } catch {}
126128
this.renderCleanup.run()
127129
this.cleanup.run()
130+
this._currentManifestKey = null
128131
}
129132

130133
render() {
131134
const project = this.Project ?? TPEN.activeProject
135+
136+
if (!project) {
137+
console.error('No project data available to render')
138+
return
139+
}
140+
141+
const manifestKey = JSON.stringify(project?.manifest ?? [])
142+
const manifestId = Array.isArray(project?.manifest) ? project.manifest[0] : project?.manifest
143+
144+
// Only render if manifest has changed or first render
145+
if (this._currentManifestKey === manifestKey) {
146+
return
147+
}
148+
this._currentManifestKey = manifestKey
149+
132150
const projectOwner = Object.entries(project.collaborators).find(([userID, u]) => u.roles.includes('OWNER'))?.[1].profile.displayName
133151
const collaboratorCount = Object.keys(project.collaborators).length
134152

@@ -150,7 +168,7 @@ class ProjectDetails extends HTMLElement {
150168
<p>
151169
${collaboratorCount < 3 ? "Collaborators: "+Object.entries(project.collaborators).map(([userID, u]) => u.profile.displayName).join(', ') : `${collaboratorCount} collaborator${collaboratorCount===1? '' : 's'}`}
152170
</p>
153-
<sequence-panel manifest-id="${project.manifest}"></sequence-panel>
171+
${manifestId ? `<sequence-panel manifest-id="${manifestId}"></sequence-panel>` : ''}
154172
`
155173
// Clear previous render-specific listeners before adding new ones
156174
this.renderCleanup.run()

interfaces/manage-project/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ TPEN.eventDispatcher.on('tpen-project-loaded', () => {
4242
leaveProjectBtn.href = `/project/leave?projectID=${projectID}`
4343
}
4444

45-
// Render the page with permissions check
46-
render()
45+
// Apply project context with permissions check
46+
applyProjectContext()
4747
})
4848

4949
document.getElementById('export-project-btn').addEventListener('click', async () => {
@@ -63,7 +63,7 @@ document.getElementById('export-project-btn').addEventListener('click', async ()
6363
})
6464
})
6565

66-
function render() {
66+
function applyProjectContext() {
6767
const isManageProjectPermission = CheckPermissions.checkEditAccess('PROJECT')
6868
if(!isManageProjectPermission) {
6969
alert("You do not have permissions to use this page.")

0 commit comments

Comments
 (0)