From 2fde5c3e25cf87cd199376807e218450a7e4cfca Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Mon, 16 Jun 2025 16:41:28 -0700 Subject: [PATCH] fix: prevent disappearing documents table when switching collections When switching collections, the $attributes store doesn't update right away so $attributes is for the old collection, but $columns is for the new collection so attr ends up being undefined leading to the error: TypeError: Cannot read properties of undefined (reading 'type') Checking attr first prevents the exception from occuring, giving enough time for $attributes to update and the table to render correctly. --- .../collection-[collection]/table.svelte | 150 +++++++++--------- 1 file changed, 76 insertions(+), 74 deletions(-) diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/table.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/table.svelte index d85591a86..42bccd017 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/table.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/table.svelte @@ -205,86 +205,88 @@ {#each $columns as { id } (id)} {@const attr = $attributes.find((n) => n.key === id)} - - {#if isRelationship(attr)} - {@const args = displayNames?.[attr.relatedCollection] ?? ['$id']} - {#if !isRelationshipToMany(attr)} - {#if document[id]} - {@const related = document[id]} - { - e.preventDefault(); - e.stopPropagation(); - goto( - `${base}/project-${page.params.region}-${page.params.project}/databases/database-${databaseId}/collection-${attr.relatedCollection}/document-${related.$id}` - ); - }}> - {#each args as arg, i} - {#if arg !== undefined} - {#if i} -  | + {#if attr} + + {#if isRelationship(attr)} + {@const args = displayNames?.[attr.relatedCollection] ?? ['$id']} + {#if !isRelationshipToMany(attr)} + {#if document[id]} + {@const related = document[id]} + { + e.preventDefault(); + e.stopPropagation(); + goto( + `${base}/project-${page.params.region}-${page.params.project}/databases/database-${databaseId}/collection-${attr.relatedCollection}/document-${related.$id}` + ); + }}> + {#each args as arg, i} + {#if arg !== undefined} + {#if i} +  | + {/if} + + {related?.[arg]} + {/if} - - {related?.[arg]} - - {/if} - {/each} - + {/each} + + {:else} + n/a + {/if} {:else} - n/a + {@const itemsNum = document[id]?.length} + { + e.stopPropagation(); + e.preventDefault(); + relationshipData = document[id]; + showRelationships = true; + selectedRelationship = attr; + }}> + Items + {/if} {:else} - {@const itemsNum = document[id]?.length} - { - e.stopPropagation(); - e.preventDefault(); - relationshipData = document[id]; - showRelationships = true; - selectedRelationship = attr; - }}> - Items - - {/if} - {:else} - {@const datetime = document[id]} - {@const formatted = formatColumn(document[id])} - {@const isDatetimeAttribute = attr.type === 'datetime'} - {#if isDatetimeAttribute} - - Timestamp - {toLocaleDateTime(datetime, true)} - - {:else if isString(attr) && attr.encrypt && showEncrypt} - - {:else if formatted.truncated} - + {@const datetime = document[id]} + {@const formatted = formatColumn(document[id])} + {@const isDatetimeAttribute = attr.type === 'datetime'} + {#if isDatetimeAttribute} + + Timestamp + {toLocaleDateTime(datetime, true)} + + {:else if isString(attr) && attr.encrypt && showEncrypt} + + {:else if formatted.truncated} + + {formatted.value} + + {#if showing} + {formatted.whole} + {/if} + + + {:else} {formatted.value} - - {#if showing} - {formatted.whole} - {/if} - - - {:else} - {formatted.value} + {/if} {/if} - {/if} - + + {/if} {/each}