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

オープン
#448 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
javascript, react
領域
frontend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
言語のデータがありません
スター
40
フォーク
9
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

hackmdio/hackmd-io-issues のほかの issue

hackmdio/hackmd-io-issues の issue をすべて見る

似ている issue

Web Dev の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。