fix: handle failed embed fetches and falsy cached() returns#2741
fix: handle failed embed fetches and falsy cached() returns#2741Diawhiz wants to merge 3 commits into
Conversation
- embed.js: add error handler to get().then() so a failed :include
fetch calls next('') instead of silently stalling page rendering
- core/util/core.js: use instead of in
cached() so functions that legitimately return falsy values ('' or 0)
have their results stored and reused correctly
|
@Diawhiz is attempting to deploy a commit to the Docsify Team on Vercel. A member of the Team first needs to authorize it. |
|
embed.js: A failed: include fetch would silently stall page rendering because the rejected promise had no error handler. Added a rejection handler that calls next('') so rendering continues gracefully on fetch failure. core/util/core.js: cached() used a truthy check (hit ||) which caused functions returning falsy values like '' or 0 to bypass the cache on every call. Changed to hit !== undefined so falsy-but-valid results are stored and reused correctly. |
There was a problem hiding this comment.
embed.js: A failed: include fetch would silently stall page rendering because the rejected promise had no error handler. Added a rejection handler that calls next('') so rendering continues gracefully on fetch failure.
core/util/core.js: cached() used a truthy check (hit ||) which caused functions returning falsy values like '' or 0 to bypass the cache on every call. Changed to hit !== undefined so falsy-but-valid results are stored and reused correctly.
There was a problem hiding this comment.
Pull request overview
This PR aims to fix two bug scenarios in Docsify’s rendering pipeline: (1) avoid stalled rendering when embedded :include fetches fail, and (2) ensure cached() correctly memoizes legitimate falsy return values (e.g., '', 0).
Changes:
- Updated
cached(fn)to treat cached falsy values as hits by checkinghit !== undefinedinstead of usinghit || .... - (Per PR title/description) Intended to add rejection handling for embed fetches, but that change does not appear to be present in the current code.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const key = isPrimitive(str) ? str : JSON.stringify(str); | ||
| const hit = cache[key]; | ||
| return hit || (cache[key] = fn(str)); | ||
| return hit !== undefined ? hit : (cache[key] = fn(str)); |
Summary
Related issue, if any:
What kind of change does this PR introduce?
For any code change,
Does this PR introduce a breaking change?
Tested in the following browsers: