[Regression] Loaded note metadata is overwritten with an empty object, causing note titles to disappear

Aperta
#448 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, react
Ambito
frontend

Direzione di ricerca

The bug sits in the note settings state path: useNoteSetting() in index-BArqKHpl.js falls back to an empty object when useNoteMetaSettingQuery() returns nothing, and NoteSettingsModal-Me4Fdoz4.js then writes that into the shared appState proxy (metadata and metadataLoaded). Start by reading those three functions and the appState setter, then find why the query briefly returns no data. Done means previously loaded metadata survives a transient empty result and the browser title stays put across a re-render.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Is this a hackmd.io issue?
Read our Official tutorial

It's on https://hackmd.io/c/tutorials/

或是中文版 https://hackmd.io/c/tutorials-tw/

What's the problem
Current behaviour

Recently, I have been experiencing an intermittent issue where note titles disappear:

  • The browser tab title reverts to the default HackMD site title.
  • The note title within the editor becomes "Untitled".
  • Reloading the page restores the correct title.
  • This issue occurs across multiple existing notes.

I started noticing this regression around the November 2026 update.

Steps to reproduce
  1. Open an existing note with a valid title.
  2. Continue using HackMD normally.
  3. Eventually, the browser tab title reverts to the default HackMD site title, and the note title within the editor becomes "Untitled".
  4. Reload the page and observe that the correct title is restored.

I have not yet identified a deterministic sequence of user actions that triggers this issue. However, I have successfully reproduced and captured the underlying metadata overwrite using Chrome DevTools, as described below.

The issue does not appear to depend on the Markdown content of a particular note.

Expected behaviour
  • The browser tab and editor should consistently display the correct note title.
  • Previously loaded metadata for the same note should not be overwritten with an empty object while new metadata is unavailable or still loading.
  • Users should not need to reload the page to restore the correct title.
Environment

I use HackMD on:

Desktop

  • OS: macOS (Apple Silicon)
  • Browser: Google Chrome
  • Browser Version: 158.0.8127.89 (Official Build) (arm64)
  • Reproduced on: November 24, 2026
  • Tampermonkey: Disabled during the final reproduction test

Mobile

  • Not tested.
Additional context
1. Technical investigation

I investigated this issue using Chrome DevTools and identified a code path where previously loaded note metadata is overwritten with an empty object.

In index-BArqKHpl.js, useNoteSetting() falls back to an empty object when metadata query data is unavailable:

function useNoteSetting(e, t) {
    let [n, r] = useNoteMetaSettingQuery(e);
    let i = n || {};

    let a = {
        values: i,
        // ...
        loaded: r && n === i
    };

    // ...
    return a;
}

In NoteSettingsModal-Me4Fdoz4.js, the returned values are obtained as follows:

let {
    values: n,
    actions: r,
    loaded: i
} = x(Ye, e.markdownParser);

These values are then propagated to the global application state:

h = () => {
    st.metadata = n;
    st.metadataLoaded = i;
    st.forceUpdateView();
}

There appears to be no guard preventing unloaded metadata from overwriting previously loaded metadata.

2. State update and notification

In appState-PB6khxMh.js, the Proxy setter synchronously notifies subscribers after updating a property:

set(e, t, n) {
    return e[t] = n,
        X.forEach(r => r(e, t, n)),
        true;
}

In frontend-BAkmRvza.js, a subscriber triggers the browser title update whenever the metadata changes:

Mr((e, t) => {
    t === "metadata" && I5()
})

The title update ultimately retrieves the note title through the following function in extra-Dypugcex.js:

function Bm(e) {
    return q.metadata?.title || null;
}

If the title is unavailable, the browser tab title falls back to the default HackMD site title.

3. Debugging evidence

I placed a conditional breakpoint immediately before the assignment in the application state Proxy setter:

t === "metadata" && !!e[t]?.title && !n?.title

With Tampermonkey disabled, the breakpoint was triggered, and I captured the following values before the assignment:

{
    previousTitle: "<valid note title>",
    previousLoaded: true,
    previousKeys: [
        "title",
        "bookRenderer",
        "description",
        "contributors",
        "breaks"
    ],
    incomingTitle: undefined,
    incomingKeys: [],
    visibility: "visible",
    timestamp: "2026-11-24T09:02:11.559Z"
}

This confirms that previously loaded metadata containing a valid title and four other properties is about to be replaced with an empty object.

In an earlier debugging session, I also captured the following values inside the NoteSettingsModal callback, after the metadata assignment but before the metadataLoaded assignment:

{
    metadataKeys: [],
    incomingTitle: undefined,
    incomingMetadataLoaded: false,
    currentMetadataLoaded: true,
    currentTitle: undefined,
    sameObject: true
}

The browser title computation returned:

{
    currentTitle: "<valid note title> - HackMD",
    computedTitle: "HackMD - Markdownで知識ベースを共作",
    loaded: true,
    J7: false,
    visibility: "visible"
}

After resuming JavaScript execution in that session, the browser tab title reverted to the default HackMD site title, and the editor displayed "Untitled".

4. Call stack

The captured call stack was:

I5          frontend-BAkmRvza.js:703
(anonymous) frontend-BAkmRvza.js:711
(anonymous) appState-PB6khxMh.js:1
set         appState-PB6khxMh.js:1
h           NoteSettingsModal-Me4Fdoz4.js:3
[React internal frames]
5. Possible cause and suggested direction

Based on the above investigation, there appear to be two issues:

  • An unloaded metadata result can overwrite previously loaded metadata with an empty object.
  • metadata and metadataLoaded are updated separately, allowing subscribers to observe an inconsistent intermediate state.

Consider preserving previously loaded metadata while new metadata for the same note is unavailable or still loading.

It may also be worth reviewing whether these two properties should be updated atomically before notifying subscribers.

I have not yet identified why useNoteMetaSettingQuery() temporarily returns unavailable data.

Although multiple metadata properties are cleared from the client-side application state, I have not observed any evidence of persistent server-side data loss.

6. Related issues
  • #418
  • #446

I have also been experiencing the title renaming issue described in #418 and #446 on macOS with Google Chrome.

These issues may share an underlying metadata synchronization problem.

However, I am opening a separate issue because this report specifically concerns previously loaded metadata being overwritten with an empty object, even without an intentional title change.

The debugging evidence above demonstrates that this affects not only the note title but also other metadata properties in the client-side application state.

I have not yet confirmed whether all three issues share the same root cause.

Thank you for looking into this.

01_metadata_overwrite_before_assignment 02_unloaded_metadata_state 03_note_settings_modal_assignment 04_use_note_setting_hook 05_proxy_setter_call_stack 06_computed_fallback_title
Lingua principale
Nessun dato sulla lingua
Stelle
40
Fork
9
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di hackmdio/hackmd-io-issues

Tutte le issue di hackmdio/hackmd-io-issues

Issue simili

Altre issue su Web Dev

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.