Skip to content

fix(irify): export full report content when downloading Word#3956

Merged
b1rdfree merged 2 commits into
masterfrom
fix/irify-word-export
Jul 14, 2026
Merged

fix(irify): export full report content when downloading Word#3956
b1rdfree merged 2 commits into
masterfrom
fix/irify-word-export

Conversation

@wlingze

@wlingze wlingze commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Wait for all paginated report items to render via flushSync and useLayoutEffect before capturing DOM for Word export, so multi-page reports include content beyond the first preview page.

Wait for all paginated report items to render via flushSync and
useLayoutEffect before capturing DOM for Word export, so multi-page
reports include content beyond the first preview page.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

PR CI 汇总

状态:全部通过

  • ✅ i18n(zh/en)
  • ✅ ESLint(renderer src/main)
  • ✅ TypeScript(renderer src/main)
  • ✅ ESLint(engine-link-startup)
  • ✅ TypeScript(engine-link-startup)
  • ✅ 图片/视频体积
  • ○ Vitest(main / renderer / engine-link;test 同目录·别名·相对路径)(skipped)
  • ✅ Prettier

由 pull_request test workflow 自动生成

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Word export for multi-page reports by temporarily rendering the full set of report items (instead of only the currently paginated preview page) and waiting for the DOM to finish rendering before capturing HTML for doc generation.

Changes:

  • Added a Word-export-only render path (wordExportItems / displayReportItems) to render all report items for capture.
  • Introduced a DOM-ready synchronization mechanism using flushSync + useLayoutEffect + requestAnimationFrame.
  • Refactored Word export flow to wait for full render (and ECharts init) before calling HTML-to-Docx conversion.

Comment on lines +428 to +437
useLayoutEffect(() => {
if (!wordExportItems?.length) return
const frame = requestAnimationFrame(() => {
requestAnimationFrame(() => {
wordExportRenderReadyRef.current?.()
wordExportRenderReadyRef.current = null
})
})
return () => cancelAnimationFrame(frame)
}, [wordExportItems])
Comment on lines 542 to 546
if (isEchartsToImg.current) {
isEchartsToImg.current = false
// 使用html2canvas将ECharts图表转换为图像
const echartsElements = contentHTML.querySelectorAll('[data-type="echarts-box"]')
const promises = Array.from(echartsElements).map(async (element) => {
const echartType = (element as HTMLElement).getAttribute('echart-type')
Comment on lines +573 to +591
const downloadWord = useMemoizedFn(async () => {
const fullItems = allReportItems.flat()
if (!fullItems.length) return

setDownloadLoading(true)
try {
const renderReady = waitForWordExportDom()
flushSync(() => {
setWordExportItems(fullItems)
})
await renderReady
// 多页报告含图表时需额外等待 ECharts 初始化
await new Promise((resolve) => setTimeout(resolve, 500))
await captureWordHtml()
} finally {
setWordExportItems(null)
setDownloadLoading(false)
}
})
@b1rdfree b1rdfree merged commit d08c9fb into master Jul 14, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants