fix(pwa): wrap writePwaManifest in try-catch to prevent build failure - #4429
Closed
88lin wants to merge 2 commits into
Closed
fix(pwa): wrap writePwaManifest in try-catch to prevent build failure#442988lin wants to merge 2 commits into
88lin wants to merge 2 commits into
Conversation
fs.writeFileSync was called without error handling. When BUILD_MODE is enabled and public/manifest.json is not writable (e.g. read-only filesystem in build/export environments), the write failure would throw and abort the site data conversion process. Wrap the write logic in try-catch; on failure, log a warning with the path and error details, then continue gracefully. Note: This code path is guarded by BUILD_MODE and only runs during build/export, not during normal SSR. The original report's claim of '500 error on every page' was overstated — the primary risk is build/export interruption, not runtime SSR failure.
Add tests that mock a read-only filesystem to verify: - writePwaManifest does not throw when fs.writeFileSync fails - warning contains the failure reason - manifestWritten only set on successful write - write skipped when BUILD_MODE !== 'true'
|
@88lin is attempting to deploy a commit to the tangly1024's projects Team on Vercel. A member of the Team first needs to authorize it. |
Member
Author
|
关闭此 PR。 原因经复核,当前 try-catch 实现不建议原样合并:
建议
|
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.
问题
writePwaManifest使用fs.writeFileSync直接写入public/manifest.json,在只读文件系统或权限不足时会抛出异常并中断整个构建流程。PWA manifest 写入失败不应阻止站点构建。修复方案
fs.writeFileSync包裹在try-catch中,写入失败时仅打印警告而非崩溃__tests__/lib/pwa.server.test.js,mock 只读文件系统验证不抛异常测试
yarn build成功变更文件
lib/pwa.server.js__tests__/lib/pwa.server.test.js