Skip to content

fix: compatibility with Obsidian 1.7+; migrate build to esbuild - #81

Open
edejong-source wants to merge 2 commits into
SkepticMystic:masterfrom
edejong-source:fix/obsidian-1.7-compat
Open

fix: compatibility with Obsidian 1.7+; migrate build to esbuild#81
edejong-source wants to merge 2 commits into
SkepticMystic:masterfrom
edejong-source:fix/obsidian-1.7-compat

Conversation

@edejong-source

Copy link
Copy Markdown

Closes #78. The plugin currently doesn't load on Obsidian 1.7+ — two compatibility issues, plus a build that no longer runs on current Node.

Source fixes

1. Null-safe sidebar leaf opening. obsidian-community-lib's openView calls app.workspace.getRightLeaf(false) / getLeftLeaf(false) and immediately awaits setViewState on the result. Obsidian 1.7+ returns null from those when the sidebar panel doesn't exist, producing an unhandled TypeError on load.

This PR ships a local openView shadow in src/main.ts that falls back to app.workspace.getLeaf(true) (a new center tab) when the side leaf is unavailable. Removes the dependency on the upstream helper for view opening only — wait is still imported from obsidian-community-lib.

2. resolvedLinks indexing-wait infinite loop. resolvedLinksComplete compared Object.keys(resolvedLinks).length === noFiles against the total markdown count. Obsidian's metadataCache.resolvedLinks omits notes that have no outgoing links, so equality never satisfies on any vault containing link-less notes — the onload await wait(1000) loop spins forever. Changed === to >=.

Diagnosis for both originally posted in the issue thread by @northbridgetechnology.

Build migration

The Rollup 2.58 + @rollup/plugin-typescript 8.3 toolchain no longer transforms the entry TypeScript on current Node — the plugin's load hook silently returns null, and Rollup falls back to its native JS parser which dies on the first import type statement.

Rather than chase that, this PR migrates to esbuild + esbuild-svelte, which is what the current obsidian-sample-plugin template uses. The new esbuild.config.mjs mirrors the previous behaviour (inline source maps for dev, none for prod; obsidian + node builtins external; Svelte CSS inlined into the JS bundle). package.json scripts now invoke it. Build is ~10× faster.

The old rollup.config.js and rollup deps are left in tree — happy to remove them in a follow-up if you'd prefer that as a separate change.

Testing

  • npm run build produces a 769KB main.js with the patches inlined
  • Installed the bundle in an Obsidian 1.9 vault: plugin loads, view opens in the right sidebar (or center tab when sidebar collapsed), graph initialises on vaults with link-less notes
  • No regression in the existing a11y warnings from Svelte components (21 pre-existing)

The Rollup 2.58 + @rollup/plugin-typescript 8.3 toolchain no longer
runs cleanly on current Node — the TypeScript plugin's load hook is
not transforming the entry point, producing an "Unexpected token"
parse error on the first \`import type\` statement.

esbuild handles TypeScript + Svelte natively, reads tsconfig path
mappings, and is the build used by the current obsidian-sample-plugin
template. The new \`esbuild.config.mjs\` mirrors the previous behaviour
(inline source maps for dev, none for prod; \`obsidian\` + node
builtins external; Svelte CSS inlined into the JS bundle).

\`package.json\` scripts point at the new config; the rollup
dependencies and \`rollup.config.js\` remain in tree for now and can
be removed in a follow-up.
Two crashes prevented the plugin from loading on current Obsidian:

1. \`obsidian-community-lib\`'s \`openView\` calls \`getRightLeaf(false)\`
   and \`getLeftLeaf(false)\` without a null check. Obsidian 1.7+
   returns null from these when the sidebar panel doesn't exist,
   causing an unhandled TypeError on the subsequent \`setViewState\`.
   This commit ships a local \`openView\` shadow that falls back to
   \`getLeaf(true)\` (a new center tab) when the preferred side is
   unavailable.

2. The \`resolvedLinksComplete\` indexing-wait used strict equality
   (\`=== noFiles\`) against the total markdown count. But Obsidian's
   \`metadataCache.resolvedLinks\` omits notes that have no outgoing
   links, so the equality never satisfies on vaults that contain any
   link-less note and the plugin hung in its onload wait loop
   indefinitely. Changed to \`>= noFiles\`.

Closes SkepticMystic#78. Diagnosis originally posted in the issue thread by
@northbridgetechnology.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

For 1.11.5 obsidian version getting error when download from community plugins

1 participant