Fix CMMS-loaded file showing "Untitled" - use document_new(), not restoreOrCreate()

restoreOrCreate() revives whatever document this browser last had open in
IndexedDB - the opposite of what a job-scoped CMMS launch wants (load
this exact file, not whatever was last open in this browser, per the
comment already above in init()). It only looked fixed on a browser with
no prior Mesh:Tool history (falls through to a blank "Untitled" doc in
that case) - any browser with real history would have shown a stale
name instead of the real filename.

document_new({name}) is what actually creates a fresh document with a
given name (mirrors what File > New does), so this uses that instead,
and drops the now-redundant separate set_doc_name() call since
document_new() already does that itself.
This commit is contained in:
AI Assistant 2026-08-27 20:25:14 +10:00
commit cd5982963f

View file

@ -780,6 +780,15 @@ async function cmms_load_from_url(config) {
// enable, mesh/build.js's doc-name label. try/finally so this always
// happens, even if the fetch or file itself fails - a file that can't
// load shouldn't leave the user stuck behind the curtain either.
//
// document_new() (not restoreOrCreate()) is what actually creates a
// genuinely fresh document with the real filename - restoreOrCreate()
// revives whatever document this browser last had open (right back into
// the "not whatever was last open in this browser" problem the comment
// above is warning about), which is also why this first showed up
// titled "Untitled" instead of the real filename (2026-08-27 follow-up
// report): it only read as fixed on a fresh/empty IndexedDB, and would
// have shown a stale name on any browser with mesh history already in it.
try {
const response = await fetch(config.loadUrl);
if (!response.ok) {
@ -789,12 +798,11 @@ async function cmms_load_from_url(config) {
const buf = await response.arrayBuffer();
const name = config.originalName || 'attachment.stl';
const file = new File([buf], name, { type: 'application/octet-stream' });
await api.document.restoreOrCreate();
await document_new({ name });
load_files([file]);
} finally {
boot_done();
handles.setEnabled(api.prefs.map.space.bounds ?? false);
api.file.set_doc_name(config.originalName || 'Untitled');
broker.publish("app_ready");
}
}