Notes with empty folded top-level headers at the end of the file cannot be opened

Steps to reproduce

  1. Create the following note, name not important:
# Content Here

## More Headings
Some stuff
Many things

# Another Header

  1. Fold Another Header
  2. Switch to “Reading View”
  3. Close note tab
  4. Attempt to reopen note

Did you read and follow the Troubleshooting Guide ? [Yes/No]

Yes, recreated the bug in sandbox mode

Expected result

The note opens

Actual result

The note fails to open.
A New Tab is displayed
An error message appears in the top corner - Failed to open ""

Environment

SYSTEM INFO:
Obsidian version: 1.13.7
Installer version: 1.13.7
Operating system: Windows 11 Pro 10.0.26200
Login status: not logged in
Language: en-GB
Insider build toggle: off
Live preview: on
Base theme: adapt to system
Community theme: none
Snippets enabled: 1
Restricted mode: off
Plugins installed: 12
Plugins enabled: 11
1: Folder notes v1.8.26
2: Omnisearch v1.31.0
3: Templater v2.25.0
4: Dataview v0.5.68
5: Git v2.39.0
6: Tasks v8.4.0
7: Advanced Tables v0.23.2
8: Docxer v2.3.1
9: Figma Embed v1.0.3
10: Image Toolkit v1.4.3
11: Callout Studio v2.14.1

RECOMMENDATIONS:
Custom theme and snippets: for cosmetic issues, please first try updating your theme and disabling your snippets. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community theme and snippets.
Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community plugins.


Additional information

  • Running localStorage.removeItem('{vault_id_here}-note-fold-Path/To/Broken File.md') “fixes” the issue temporarily, in that it allows you to edit the file in Obsidian to fix the formatting. It will however break again if the repro steps are followed.

  • Error message screenshot:

  • Full stack trace:

app.js:1 RangeError: Invalid line number 0 in 11-line document
    at e.line (app.js:1:263323)
    at t.applyFoldInfo (app.js:1:2544874)
    at t.setViewData (app.js:1:3040971)
    at t.setData (app.js:1:2445391)
    at t.<anonymous> (app.js:1:2445294)
    at app.js:1:258720
    at Object.next (app.js:1:258825)
    at a (app.js:1:257543)
(anonymous) @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
s @ app.js:1
Promise.then
l @ app.js:1
(anonymous) @ app.js:1
y @ app.js:1
t.loadFile @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
y @ app.js:1
t.setState @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
y @ app.js:1
t.setState @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
a @ app.js:1
Promise.then
l @ app.js:1
(anonymous) @ app.js:1
y @ app.js:1
t.setViewState @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
(anonymous) @ app.js:1
y @ app.js:1
t.openFile @ app.js:1
t.onSelfClick @ app.js:1
t.onFileClick @ app.js:1
s @ enhance.js:1