Repository navigation
Use createDiv for widget root (plugin-review Finding 2 revisited) - #12
Merged
Merged
Conversation
Obsidian's global createDiv returns a detached element and satisfies both CodeMirror's toDOM() contract and the plugin-review scanner's prefer-create-el rule. The earlier "no change" resolution for this finding was based on a wrong assumption that all createDiv helpers append their new element. The Node-prototype method does, but the global helper doesn't (obsidian.d.ts:193). Updates docs/obsidian-review-warnings.md accordingly.
5 tasks
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-review scanner is still flagging
document.createElementat src/editor-extension.tsx:81 — the one call our 1.4.1 pass left in place. Turns out the earlier "no change" resolution was based on a wrong assumption.What the old comment claimed: all of Obsidian's
createDivhelpers append to a receiver, so we can't use them for a detached CodeMirror widget root.What's actually true: the Node-prototype
createDivappends, but the globalcreateDiv(declared at obsidian.d.ts:193) returns a detachedHTMLDivElement. That's the API the scanner wants and it satisfies CodeMirror'stoDOM()contract just fine.Change
docs/obsidian-review-warnings.mdFinding 2 flipped from "No change" to "Fixed" with the corrected reasoning.Notes
main.jsstill contains 5createElementcalls after build — those come from React 18's runtime internals, not our source. The scanner cited a source line, so a source-level fix is the right target.createDivcreates in the main window's document; if a viewer opens the editor in a popout, browsers adopt the node into the popout's document when CodeMirror appends it. Event listeners we attach (focusinstopPropagation) survive adoption.Test plan
grep -c createElement src/editor-extension.tsx→0npm run lintcleannpm test— 92/92 greennpm run buildclean