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

未关闭
#448 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

hackmdio/hackmd-io-issues 的其他 Issue

查看 hackmdio/hackmd-io-issues 的全部 Issue

相似的 Issue

更多 Web Dev Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。