Skip to content

fix: File preview in full screen and download blocked in embedded mode - #8306

Merged
shaohuzhang1 merged 1 commit into
v3from
pr@v3@fix_embed
Dec 4, 2026
Merged

shaohuzhang1 merged 1 commit into
v3from
pr@v3@fix_embed

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

fix: File preview in full screen and download blocked in embedded mode

</template>
</div>
</div>
<div ref="viewerRef" class="document-preview-viewer relative min-h-0 flex-1 overflow-auto bg-white">

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of the diff

Potential issues

  1. Placeholder hack is fragile & non-semantic
    Using two invisible / pointer-events-none buttons 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_outlined at size="18".
    • el-button carries default padding/border/margins; even with ml-0!, spacing may drift across themes or Element Plus versions.
    • tabindex="-1" is redundant on a disabled/non-focusable element but doesn't prevent screen readers from announcing it — use aria-hidden="true" as well (or better, a plain <span>/<div> with explicit width).
  2. Magic string 'EMBED'
    Comparing viewType !== '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/index fails loudly instead of silently breaking.

  3. useViewType() semantics unverified
    Confirm it returns a reactive value (ref/computed). If it returns a plain value captured once, the v-if won'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 that DocumentPreview might be rendered outside of).

  4. Reactivity via destructuring
    Existing line const { knowledgeSource, closeRightSide } = useRightSidebarStore() loses reactivity for store state if knowledgeSource is itself a ref/reactive property accessed by value; not introduced by this diff, but flag alongside the new viewType usage since both affect template reactivity.

  5. 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.

  6. 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 useViewType is 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>
<!-- 预览区域:按文件地址重建预览组件,切换文件时旧文件的加载与绘制随组件卸载取消 -->

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is my review of the added code:

Issues / Irregularities

  1. pointer-events-none with invisible is redundant and semantically confusing. invisible (visibility: hidden) already prevents pointer events, so combining both plus pointer-events-none adds noise without benefit.

  2. pointer-events-none is not a standard Tailwind utility in all setups. Tailwind uses pointer-events-none, but if this project's config deviates, it silently does nothing. Verify it exists in your Tailwind/utility-CSS build.

  3. 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.

  4. Non-breaking space (&nbsp;) 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.

  5. 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 with aria-hidden absent. Consider adding aria-hidden="true".

  6. 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.

  7. 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 (drop pointer-events-none unless 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.

@shaohuzhang1
shaohuzhang1 merged commit e45b5b6 into v3 Dec 4, 2026
3 of 4 checks passed
@shaohuzhang1
shaohuzhang1 deleted the pr@v3@fix_embed branch December 4, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant