fix: log error when saveAs is called from a web worker#1
Closed
ynsacc2024-sys wants to merge 2 commits into
Closed
fix: log error when saveAs is called from a web worker#1ynsacc2024-sys wants to merge 2 commits into
ynsacc2024-sys wants to merge 2 commits into
Conversation
Adds 4 tests covering: - web worker no-op behavior (eligrey#779, fixes silent failure from eligrey#778) - module loading via <script> tag (window.saveAs attached) - module loading via CommonJS (module.exports == window.saveAs) - no-throw sanity check for normal browser load Upstream previously had 'Error: no test specified && exit 0' as the test script, so this is the project's first real test coverage.
Fixes eligrey#778, addresses the proposal in eligrey#779. saveAs() was a silent no-op when called from a web worker, leaving developers guessing why their download didn't happen. Replace the no-op with a console.error that points to the original issue for context. Behavior change: any code path that relied on the silent no-op will now see a console error. In practice this is desirable since it surfaces a real programming error; if a stricter behavior (throw) is preferred, a follow-up can swap console.error for a thrown Error.
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.
Fixes eligrey#778 —
saveAs()was silently a no-op when called from a web worker,leaving developers guessing why their download didn't happen. This change
replaces the silent no-op with a
console.errorthat includes a link to theoriginal issue for context.
Changes
src/FileSaver.js(line 76–77):/* noop */→console.error('…')echo "Error: no test specified" && exit 0as itsnpm testscript, so this is its firstreal test coverage.
npm test.Behavior change
Any code path that relied on the silent no-op will now see a console error.
This is intentional — silent failures are worse than visible ones. If a
stricter behavior (throw) is preferred, happy to swap
console.errorfor athrown
Errorin a follow-up.Closes eligrey#779 (which proposed essentially this fix 3 years ago).