I am not entirely sure if this topic is correct. The bug will appear for everyone, but the declarative settings API is still very new and the official settings don’t use lists, so I guess only developers will stumble upon it for now.
Steps to reproduce
- Open a settings tab containing a list of pages (use example code below)
- Create
PluginSettingTab - Using the declarative settings API create:
- a list
- items of type
page - some trigger on the main settings page to call
update()
- compile → run → open settings tab
- Create
- trigger
update() - Click on a sub page
- navigate back
Did you follow the troubleshooting guide? [Y/N]
Yes.
Expected result
I would expect to land on the main settings tab.
Actual result
I see the same sub page again and need to navigate back a second time to reach the main settings page again.
Environment
SYSTEM INFO:
Obsidian version: 1.13.1
Installer version: 1.8.7
Operating system: Windows 11 Home 10.0.26200
Login status: logged in
Language: en
Catalyst license: insider
Insider build toggle: on
Live preview: on
Base theme: adapt to system
Community theme: none
Snippets enabled: 0
Restricted mode: off
Plugins installed: 1
Plugins enabled: 1
1: My Plugin v0.0.0
Additional information
- It seems like instead of navigating to
/Sub page 1the app navigates to/Sub Page 1/Sub Page 1 - After clicking on the sub page (step 3) the double navigation can also be seen in the animation
- It only happens for the first navigation after
update() - It doensn’t seem to matter which sub page is clicked or if it was clicked before
- The docs contradict themselves, if calling
update()while the settings are open, is a safe action-
It is presented as a recommended solution here:
If what your tab displays depends on state that changes elsewhere […], the tab can go stale while the user has it open. Call
this.update()to re-rungetSettingDefinitions()and rebuild. -
It is implied to be unsafe here:
update()is safe to call when the settings modal is closed -
Anyway I see no other way to add, rename and remove sub pages, without calling
update()
-
- It’s kind of related to another post of mine: https://forum.obsidian.md/t/how-to-properly-rename-lists-of-sub-pages-in-a-seettings-tab/115339?u=resource1909
Example code
import { Plugin, PluginSettingTab, SettingDefinitionItem } from "obsidian";
export class ExampleSettingsTab extends PluginSettingTab {
constructor(plugin: Plugin) {
super(plugin.app, plugin);
}
getSettingDefinitions(): SettingDefinitionItem[] {
return [
{
type: "list",
heading: 'Sub pages',
items: [
{
type: "page",
name: "Sub page 1",
searchable: true,
items: [ { name: "Test" } ]
},
{
type: "page",
name: "Sub page 2",
searchable: true,
items: [ { name: "Test" } ]
}
]
},
{
name: "Trigger Update",
action: () => this.update()
}
];
}
}
Gif
