Repository navigation
fix: File preview in full screen and download blocked in embedded mode - #8306
Conversation
| </template> | ||
| </div> | ||
| </div> | ||
| <div ref="viewerRef" class="document-preview-viewer relative min-h-0 flex-1 overflow-auto bg-white"> |
There was a problem hiding this comment.
Review of the diff
Potential issues
-
Placeholder hack is fragile & non-semantic
Using twoinvisible/pointer-events-nonebuttons purely as layout spacers to reserve width for overlay buttons injected by an external embed script is brittle:- The external script's button sizes/styles are not guaranteed to match
icon_magnify_outlined/icon_close_outlinedatsize="18". el-buttoncarries default padding/border/margins; even withml-0!, spacing may drift across themes or Element Plus versions.tabindex="-1"is redundant on adisabled/non-focusable element but doesn't prevent screen readers from announcing it — usearia-hidden="true"as well (or better, a plain<span>/<div>with explicit width).
- The external script's button sizes/styles are not guaranteed to match
-
Magic string
'EMBED'
ComparingviewType !== 'EMBED'against a raw literal couples this component to the enum's serialized value. Prefer importing the enum/const (e.g.ViewType.EMBED) so renaming or refactoring in@/conversation-panel/view/indexfails loudly instead of silently breaking. -
useViewType()semantics unverified
Confirm it returns a reactive value (ref/computed). If it returns a plain value captured once, thev-ifwon't update on view-type changes. Also check whether it requires being called inside a component setup with proper injection context (it's fine here, but worth confirming it doesn't rely on a provider thatDocumentPreviewmight be rendered outside of). -
Reactivity via destructuring
Existing lineconst { knowledgeSource, closeRightSide } = useRightSidebarStore()loses reactivity for store state ifknowledgeSourceis itself a ref/reactive property accessed by value; not introduced by this diff, but flag alongside the newviewTypeusage since both affect template reactivity. -
Behavior gap: no way to close in EMBED mode from this component
Hiding the close button means the only exit is the overlay-provided one. If the embed script fails to load/inject, users are trapped. Consider keeping a fallback (e.g., render the close button if overlay isn't detected) or documenting the contract. -
Comment duplication / accuracy
The new comments are helpful but assume the overlay positions buttons at the top-right of the iframe's outer frame. Verify this holds in all embed containers and locales (RTL) — in RTL the reserved order should be mirrored.
Optimization suggestions
- Replace the spacer buttons with
<span class="w-9 shrink-0" aria-hidden="true" />(or exact computed widths), removing icon import/cost and semantic noise. - Extract the visibility condition into a named
computed, e.g.const canCloseFromPanel = computed(() => viewType.value !== ViewType.EMBED), improving readability and testability. - Add a unit/e2e test asserting the close button is absent in EMBED and present otherwise.
- Consider CSS custom property / shared constant for the reserved width so the embed script and this component stay in sync (single source of truth).
- If
useViewTypeis cheap, fine; if it triggers subscriptions, ensure it's cleaned up (onMounted/onBeforeUnmount already exist for other resources — verify none leak).
Minor
ml-0!relies on Tailwind important modifier plus Element Plus specificity; prefer a scoped class in the<style>block for robustness.- No irregular syntax in the diff itself; the template/script structure is valid.
| </template> | ||
| </div> | ||
| </div> | ||
| <!-- 预览区域:按文件地址重建预览组件,切换文件时旧文件的加载与绘制随组件卸载取消 --> |
There was a problem hiding this comment.
Here is my review of the added code:
Issues / Irregularities
-
pointer-events-nonewithinvisibleis redundant and semantically confusing.invisible(visibility: hidden) already prevents pointer events, so combining both pluspointer-events-noneadds noise without benefit. -
pointer-events-noneis not a standard Tailwind utility in all setups. Tailwind usespointer-events-none, but if this project's config deviates, it silently does nothing. Verify it exists in your Tailwind/utility-CSS build. -
ml-0!(important modifier) looks suspicious. In Tailwind v3 the important modifier is!ml-0; the trailing!syntax is Tailwind v4. Mixing conventions here suggests either a misconfiguration or an accidental typo — confirm which Tailwind version this repo targets. This is the most likely bug because if the syntax is wrong, the class won't be applied at all. -
Non-breaking space (
) inside the button instead of self-closing tag. Either use<el-button ... />(if Element Plus supports it) or place the icon directly without stray whitespace to keep markup clean. -
tabindex="-1"is good for removing from tab order, but these are placeholder buttons — using actual<el-button>elements rather than styled<span>/<div>placeholders creates empty focusable/interactive elements that could confuse assistive technology even witharia-hiddenabsent. Consider addingaria-hidden="true". -
Hardcoded duplication. The two placeholder buttons duplicate size/class strings. If the layout ignores these frequently, extract into a small local component (
<PlaceholderBtn :icon="...">) to reduce drift between the real and placeholder buttons. -
Comment is verbose/Chinese while the rest of the file appears English-commented (line 83 area). Consistency suggestion only.
Optimization Suggestions
- Add
aria-hidden="true"to both placeholder buttons. - Simplify classes to just
invisible ml-0(droppointer-events-noneunless you actually need to keep the element clickable-but-transparent for layout). - Replace
ml-0!with the correct important syntax for your Tailwind version, or remove the important flag entirely if not needed. - Document why the placeholders must mirror the real buttons' size — otherwise future refactors may break alignment silently.
- Consider rendering the placeholders only when the iframe branch (embedded script) is actually active rather than as a blanket
v-else, to avoid dead DOM in normal previews.
fix: File preview in full screen and download blocked in embedded mode