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

Đang mở
#448 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, react
Lĩnh vực
frontend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Không có dữ liệu ngôn ngữ
Star
40
Fork
9
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của hackmdio/hackmd-io-issues

Tất cả issue của hackmdio/hackmd-io-issues

Issue tương tự

Thêm issue về Web Dev

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.