You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⚠️ Low — loadContent is called without awaiting inside useEffect, silencing unhandled rejections
File:packages/pluggableWidgets/document-viewer-web/src/components/DocxViewer.tsx line 42 Note:loadContent(response) is an async function but its returned Promise is not awaited and has no .catch() attached inside the useEffect chain. If renderAsync throws after the fetch resolves, the error is swallowed by the try/catch inside loadContent — but if the ref check (localRef.current) passes and then renderAsync rejects (e.g. due to an abort mid-render), the catch in loadContent handles it correctly. This is functionally fine today; however, chaining .catch() on the call makes the intent explicit and avoids a potential lint warning:
Or simply flatten the chain so both steps are in the same .then:
.then(res=>res.arrayBuffer()).then(response=>loadContent(response)).catch((_error: any)=>{if(!signal.aborted){setDocumentStatus({status: DocumentStatus.error,message: "Failed to load DOCX document"});}});
⚠️ Low — Abort signal not forwarded into renderAsync
File:packages/pluggableWidgets/document-viewer-web/src/components/DocxViewer.tsx line 23 Note: The AbortController signal is passed to fetch and guards the .catch(), but renderAsync from docx-preview v0.4 does not receive the signal. If the component unmounts mid-render, the abort stops the fetch and the .catch is guarded, but an in-progress renderAsync will continue running and may call setDocumentStatus on an unmounted component. Adding a mounted-ref guard or checking signal.aborted before calling setDocumentStatus inside loadContent's catch block would make this fully safe:
}catch(_error: any){if(!signal.aborted){setDocumentStatus({status: DocumentStatus.error,message: "Failed to load DOCX document"});}}
This requires threading signal into loadContent (or the useCallback closure).
Positives
The switch from the two-step parseAsync + renderDocument to the single renderAsync call is a correct and clean migration to the docx-preview v0.4 API — noticeably less boilerplate.
Adding a .catch() with an signal.aborted guard on the fetch chain is a genuine improvement; the original code had no error handling at the fetch layer.
CHANGELOG entry is present, follows Keep a Changelog format, and is correctly placed in [Unreleased].
The comment // Keep generated styles out of the document head. explains the non-obvious pattern of passing a dummy styleContainer.
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
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.
Pull request type
Description