fix: plugin not working on current Logseq versions#96
Open
phillix2 wants to merge 1 commit intosawhney17:mainfrom
Open
fix: plugin not working on current Logseq versions#96phillix2 wants to merge 1 commit intosawhney17:mainfrom
phillix2 wants to merge 1 commit intosawhney17:mainfrom
Conversation
Three bugs prevented the plugin from working on recent Logseq:
1. blockArray never populated — In current Logseq, every onChanged event
includes an outlinerOp (save-block, insert-blocks). The old code expected
some events WITHOUT outlinerOp to accumulate block UUIDs, then process
them on insert-blocks. Since all events had an outlinerOp, blocks always
went to the processing branch with an empty array. Fix: process blocks
directly from e.blocks in the event.
2. Regex crash on certain page names — The Chinese character regex
(?<!\[)PAGE(?!\]) crashed for page names containing special chars
(like UUIDs with dashes), causing "Range out of order in character class"
errors that killed ALL page processing. Fix: added try/catch per page,
fixed Chinese detection to require at least one Chinese char (+ not {0,}).
3. mod+p shortcut conflict — The default parseSingleBlockKeybinding (mod+p)
conflicts with Logseq's :editor/add-property. Changed to alt+shift+l.
Additional improvements:
- Added isProcessing guard to prevent updateBlock → onChanged feedback loop
- Null safety for e.blocks[0] access
- try/catch around all datascript queries (fail gracefully)
- Protected entire property lines (key AND values) from auto-linking
- Protected existing [[links]] before processing
- Upgraded @logseq/libs from 0.0.6 to 0.0.17
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The plugin stopped working on recent Logseq versions (0.10+). Three bugs were identified and fixed:
blockArraynever populated (main issue) — In current Logseq, everyonChangedevent includes atxMeta.outlinerOp(save-block,insert-blocks, etc.). The old code expected some events WITHOUToutlinerOpto accumulate block UUIDs inblockArray, then process them wheninsert-blocksfired. Since ALL events now have anoutlinerOp, blocks always went to the processing branch with an empty array → plugin did nothing.e.blocksin the event instead of the intermediateblockArray.Regex crash on certain page names — The Chinese character regex
(?<!\[)PAGE(?!\])crashed for page names containing special characters (like UUIDs with dashes), throwing"Range out of order in character class"errors that killed processing for ALL pages.try/catchper page so one bad regex doesn't break everything. Fixed Chinese detection to require at least one Chinese character (+instead of{0,}).mod+pshortcut conflict — The defaultparseSingleBlockKeybinding(mod+p) conflicts with Logseq's built-in:editor/add-property. (Relates to shortcut does not work properly #81, Error message "Keyboard shortcut conflicts with existing shortcut" #68)alt+shift+l.Additional improvements
isProcessingguard to preventupdateBlock→onChangedfeedback loop (relates to Error message "This plugin takes too long to load" #67, PR fix: Prevent multiple executions of db.onChanged callback #92)e.blocks[0]accesstry/catcharound all datascript queries (fail gracefully instead of silently breaking)key::(fixes Automatic parsing feature parses page titles and page properties #86, Properties and code converted to link #90)[[links]]are protected before processing to avoid double-linking@logseq/libsfrom 0.0.6 to 0.0.17Related Issues
Fixes #78 (Escaping out of a block doesn't parse for links — now listens to
save-block)Fixes #67 (Plugin takes too long to load — feedback loop prevention)
Fixes #81 (Command+P shortcut not working — changed default binding)
Fixes #68 (Keyboard shortcut conflicts)
Fixes #86, #90 (Properties and code converted to links)
Incorporates the idea from PR #92 (multiple
onChangedfirings)Test plan
Ctrl+Shift+L), type text containing an existing page name, press Enter → should auto-linkkey:: value) are NOT auto-linked[[links]]are not double-linked🤖 Generated with Claude Code