fix(irify): export full report content when downloading Word#3956
Merged
Conversation
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>
Contributor
PR CI 汇总状态:全部通过
由 pull_request test workflow 自动生成 |
Contributor
There was a problem hiding this comment.
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
approved these changes
Jul 14, 2026
EmbraceAn
approved these changes
Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.