Repository navigation
fix: honor question permissions in paragraph dialogs - #8288
Conversation
| :show="showQuestions" | ||
| :knowledge-id="targetKnowledgeId" | ||
| :document-id="targetDocumentId" | ||
| :paragraph-id="targetParagraphId" |
There was a problem hiding this comment.
The diff is small, but there are a few things to verify and potential improvements:
-
Confirm
ParagraphQuestionsno longer requiresshow- You removed both
:show="showQuestions"and theshowprop usage. If the child component still declaresshowas a required prop, or uses it internally for conditional rendering/data loading, this will cause a warning or behavior change. - Either remove
showfrom the child API or keep passing it.
- You removed both
-
v-ifchanges behavior compared with ashowpropv-ifunmountsParagraphQuestionswhen permission is false. The old:showapproach likely kept it mounted but hidden.- This can be an optimization because the child is not created when not needed.
- However, it also means:
- Child internal state is lost when permission becomes false.
- Lifecycle hooks, watchers, and data fetching inside the child will not run until permission is true.
- If permission toggles frequently, the component will be destroyed/recreated.
- If preserving child state is important, use
v-showor continue using ashowprop.
-
Avoid calling
hasProblemReadPermission()directly in the template- It works, but it is called on every render.
- A computed value is clearer and cached:
const canReadProblems = computed(() => hasProblemReadPermission())<ParagraphQuestions v-if="canReadProblems" ... /> - This is especially useful if the permission check is non-trivial or reused elsewhere.
-
Ensure reactivity of the permission check
v-if="hasProblemReadPermission()"will update only ifhasProblemReadPermission()depends on reactive state.- If it reads from a non-reactive global or cached value, the template will not re-render when permissions change.
-
Check for remaining references to
showQuestions- You removed the
showQuestionscomputed. Make sure it is not referenced anywhere else in the file or exposed to the template.
- You removed the
-
Check
v-modelbehavior on remount- With
v-model="relatedQuestions"andv-if, the child will remount when permission becomes true. - Verify that
ParagraphQuestionsdoes not emit an unintendedupdate:modelValueon mount that could overwriterelatedQuestions.
- With
-
Consider the permission dependency on IDs
- If
hasProblemReadPermission()depends ontargetKnowledgeId,targetDocumentId, ortargetParagraphId, make sure those values are valid before rendering. Otherwise, the child may be shown/hidden incorrectly during initial load.
- If
Overall, the change is reasonable if the goal is to avoid mounting ParagraphQuestions when the user lacks read permission. The main risks are the child component’s show prop contract and the behavioral difference between hiding and unmounting. Using a computed canReadProblems instead of a template method call would be a small readability and performance improvement.
| <aside v-loading="loading" class="mk-gray-card-lg flex-column w-60 shrink-0"> | ||
| <div class="mb-4 flex-between shrink-0 gap-3"> | ||
| <h4>{{ t('knowledge.paragraph.relatedQuestions.label') }}</h4> | ||
| <!-- 添加关联问题 --> |
There was a problem hiding this comment.
The diff removes the show prop and its v-if guard, so the <aside> is now always rendered. Here are the issues and suggestions:
Potential Issues
-
Loss of conditional rendering: Previously the parent could hide the panel via
:show="false". Now visibility must be controlled by the parent usingv-if/v-showon the component itself, or the panel will always mount. Confirm all call sites still want this behavior. -
Unused import / dead code: If
showwas used elsewhere (e.g., in a watcher, computed, or another branch), any leftover references will break the build or cause runtime errors. Double-check nothing else referencesshow. -
v-loadingnow runs unconditionally:v-loading="loading"will activate even when the section is conceptually hidden. Ifloadingis only meaningful while visible, gate the loading state or keep a lightweightv-showfor layout stability. -
Layout shift: With
w-60 shrink-0, the aside occupies width at all times. If it's meant to be collapsible, usev-show(keeps layout/DOM) vsv-if(removes DOM) deliberately — right now you've effectively forced it permanently visible. -
Breaking change to the public prop API: Removing
showfromdefinePropsis a breaking change for any consumer passing it. Vue will emit an "extraneous non-props attribute" warning and attachshowas an HTML attribute on the root element instead of ignoring it. Consider deprecating it first or updating all usages atomically.
Suggestions
- If the intent is "parent controls visibility," prefer not adding a prop and letting the parent wrap with
v-if="show". This is cleaner and avoids a redundant prop. - If you keep removing
show, ensure every call site is updated in the same changeset and remove now-dead imports/variables. - Consider whether the always-mounted
resourceApi/relatedProblemsmodel subscriptions cause unnecessary work when the panel is hidden; lazy-mount if expensive. - Verify tests/stories that referenced the
showprop are updated.
Summary: The change is safe only if (a) all consumers no longer pass show, (b) no other code references show, and (c) the panel genuinely should always render. Otherwise, expect Vue attribute warnings and unintended always-visible UI.
| :show="knowledgeQuestionPermission()" | ||
| :knowledge-id="targetKnowledgeId" | ||
| :document-id="targetDocumentId" | ||
| /> |
There was a problem hiding this comment.
Review of the Diff
What changed
- Before:
ParagraphQuestionswas always rendered; visibility was delegated to the child via a:showprop driven byknowledgeQuestionPermission(). - After: the component is conditionally rendered with
v-if="knowledgeQuestionPermission()", and theshowprop is removed.
Potential issues
-
Permission function called during render —
knowledgeQuestionPermission()is invoked on every re-render. If it performs non-trivial work (API calls, store lookups, deep checks), this hurts performance. Prefer a computed:const canShowQuestions = computed(() => knowledgeQuestionPermission())then
v-if="canShowQuestions". A computed also avoids redundant recomputation across renders. -
Loss of child-side control — Removing
:showshifts behavior from "child decides how to hide" (e.g., keeps state/mounted instance) to "parent unmounts." Confirm the child doesn't rely on being mounted while hidden (e.g., internal watchers, form init, telemetry). If it does,v-showmay be more appropriate thanv-if. -
v-if+v-modelinteraction — When permission flips false→true, the component remounts. Any local edits inrelatedQuestionsheld inside the child could be reset. Ensurev-modelbinding survives remount correctly. -
Reactivity assumption —
v-ifrequiresknowledgeQuestionPermission()to be reactive (depends on refs/reactive state). If permission comes from a non-reactive source (plain function reading a module variable), the block won't update. Verify reactivity. -
Stale prop type / unused prop in child — Since
:showwas removed, check thatParagraphQuestionsno longer declares/expects a requiredshowprop and that its internal logic doesn't still gate on it (dead code / warnings). -
Naming consistency —
knowledgeQuestionPermission()reads like a boolean getter; consider naming ithasKnowledgeQuestionPermissionfor clarity, or exposing it as a computed boolean directly in the template. -
Nested single-condition
v-if— Fine here, but if more conditions are added later, consider computing a single predicate to keep the template clean.
Optimization suggestion
<script setup>
const canShowQuestions = computed(() => knowledgeQuestionPermission())
</script>
<template>
<ParagraphQuestions
v-if="canShowQuestions"
v-model="relatedQuestions"
:knowledge-id="targetKnowledgeId"
:document-id="targetDocumentId"
/>
</template>
Verdict
The change itself is reasonable and arguably cleaner (permission gating at the parent avoids rendering an unauthorized component at all). Main risks are: calling a possibly non-reactive/expensive function in the template, and behavioral differences from remount vs hide. Address those two and the diff is sound.
fix: honor question permissions in paragraph dialogs