Repository navigation
fix: restore document list pagination and scope detail scrolling - #8302
Conversation
|
|
||
| const documentQuery = ref<Dict<unknown>>({}) | ||
| const orderBy = ref<string>() | ||
| const creatorOptions = ref<OptionItem<string>[]>([]) |
There was a problem hiding this comment.
The diff is generally reasonable, but there are several things to check/fix. I’m assuming pagination-return handles router/history-state storage correctly; without its implementation, some risks below are conditional.
Potential issues
-
Unhandled promise rejection
void router.push(detailLocation).then((failure) => { if (!failure) saveDocumentPagination(...) })
There is no
.catch(). Ifrouter.pushrejects unexpectedly, orsaveDocumentPaginationthrows inside.then, this becomes an unhandled rejection. Preferasync/awaitwithtry/catch, or add.catch(). -
Saved pagination is not validated
currentPage: savedPagination?.currentPage ?? 1, pageSize: savedPagination?.pageSize ?? 20,
The saved values come from browser history/storage and can be stale or invalid. Validate:
currentPageis an integer>= 1pageSizeis one of the allowed page-size options- after
totalis loaded, clampcurrentPageto the last valid page and refetch if needed
Otherwise users can land on an empty page after deleting documents or changing filters.
-
Restored page can exceed the actual total
totalis reset to0, and the savedcurrentPageis applied before data is loaded. If the saved page no longer exists, the table may render empty. After fetch, do something like:const maxPage = Math.max(1, Math.ceil(total / pageSize)) if (currentPage > maxPage) currentPage = maxPage
-
Location key normalization
detailLocationis passed to bothrouter.pushandsaveDocumentPagination. Vue Router may normalize query/params. Ifpagination-returndoes not resolve the location itself, use the resolved path for the storage key:const detailFullPath = router.resolve(detailLocation).fullPath
Otherwise the saved key may not exactly match the route later read by
takeDocumentPagination. -
Sharing
route.queryby referencequery: route.query
It is safer to clone it:
query: { ...route.query }
This avoids accidental coupling to the reactive route object.
-
KeepAlive / component reuse
const savedPagination = takeDocumentPagination(router)
This runs only during
setup(). If the list component is kept alive or reused when returning from the detail page, the saved pagination will not be consumed. In that case, move restoration intoonActivated()or a route watcher. -
Scoping of saved pagination
Make suresaveDocumentPagination/takeDocumentPaginationare scoped by knowledge base / resource / list route. Otherwise pagination from one document list could leak into another. -
void router.push(...).then(...)is misleading
It works, but thevoidmakes it look like errors are intentionally ignored. A clearer form would be:router.push(detailLocation) .then((failure) => { ... }) .catch((error) => { ... })
or better:
async function handleOpenParagraph(...) { ... try { const failure = await router.push(detailLocation) if (failure) return saveDocumentPagination(router, listLocation, detailLocation, { currentPage, pageSize }) } catch (error) { // log/handle } }
Minor note
handleOpenParagraph references paginationConfig before its declaration, but since the function is only called after setup completes, this is not a runtime TDZ issue. It is still slightly harder to read; declaring paginationConfig earlier might be cleaner.
Recommended fix summary
- Add error handling around
router.pushandsaveDocumentPagination. - Validate/normalize restored
currentPageandpageSize. - Clamp the restored page after
totalis known. - Ensure the saved detail-location key is resolved/normalized consistently.
- Clone
route.query. - Use
onActivated/route watcher if the list page can be kept alive. - Ensure pagination storage is scoped to the correct knowledge/resource list.
| .resource-detail-layout :deep(main > .el-scrollbar > .el-scrollbar__wrap > .el-scrollbar__view:has(> .mk-scrollbar-fill-height)) { | ||
| height: 100%; | ||
| } | ||
| </style> |
There was a problem hiding this comment.
The diff is syntactically valid, but there are several fragility/compatibility concerns:
-
:has()browser support:has()is not supported in older browser versions. If the project still supports older Safari/Firefox/enterprise browsers, this layout rule will silently fail.- PostCSS/autoprefixer generally won’t transpile
:has(). Use a fallback or avoid:has()if support is required.
-
Tight coupling to Element Plus /
MkViewLayoutinternal DOM- This selector depends on the exact DOM chain:
main > .el-scrollbar > .el-scrollbar__wrap > .el-scrollbar__view. - Any internal change in
MkViewLayoutor Element Plus can break it silently. - Prefer exposing a prop/class from
MkViewLayoutor applying a dedicated class to the scrollbar view instead of piercing internal implementation details.
- This selector depends on the exact DOM chain:
-
Assumption that
class="resource-detail-layout"lands on the expected root- This works only if
MkViewLayouthas a single root element and normal attribute fallthrough. - If it uses a fragment root,
inheritAttrs: false, or redirects attrs, the selector may not match.
- This works only if
-
height: 100%may be ineffectiveheight: 100%only resolves correctly if the parent chain has a definite height.- In flex layouts, you often need
flex: 1; min-height: 0;rather than onlyheight: 100%. - Verify this does not create nested scrollbars or clip content.
-
:has(> .mk-scrollbar-fill-height)is direct-child-only- If an extra wrapper is introduced around
.mk-scrollbar-fill-height, the rule stops applying. - Confirm this strict relationship is intentional.
- If an extra wrapper is introduced around
-
Potentially broad selector
.resource-detail-layout :deep(main > ...)can match nestedmainelements under the layout.- If nested layouts are possible, consider a tighter selector or a dedicated class for the target scrollbar view.
Suggested improvement: avoid :has() and internal DOM coupling by having MkViewLayout support a “fill height” class/prop, or by placing a semantic class directly on the scrollbar view. If keeping the current approach, add a browser-support fallback and document that the selector depends on Element Plus internals.
Minor: the CSS comment is in Chinese; consider matching the project’s comment-language convention.
perf: Readme
fix: restore document list pagination and scope detail scrolling