fix(reader): guard applyMarginAndGap against a torn-down view (#5022)

applyMarginAndGap re-fetches getViewSettings(bookKey) with a non-null assertion,
but it runs from effects/observers that can fire after the book is torn down,
when getViewSettings returns null. The `!` hid that, so getViewInsets /
viewSettings.showHeader threw "Cannot read properties of null (reading
'showHeader')" (READEST-2V). Bail when there is no view left to lay out.

Fixes READEST-2V

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Huang Xin 2026-07-09 16:03:29 +09:00 committed by GitHub
parent a9fb86ddc5
commit fdd13a5a6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -779,7 +779,12 @@ const FoliateViewer: React.FC<{
}, []); }, []);
const applyMarginAndGap = () => { const applyMarginAndGap = () => {
const viewSettings = getViewSettings(bookKey)!; // Invoked from effects/observers that can fire after the book is torn down,
// when getViewSettings(bookKey) returns null. The `!` assertion hid that, so
// the reads below (getViewInsets, viewSettings.showHeader) crashed on null
// (READEST-2V). Bail: there is no view left to lay out.
const viewSettings = getViewSettings(bookKey);
if (!viewSettings) return;
const viewState = getViewState(bookKey); const viewState = getViewState(bookKey);
const bookData = getBookData(bookKey); const bookData = getBookData(bookKey);
const viewInsets = getViewInsets(viewSettings); const viewInsets = getViewInsets(viewSettings);