obsidian-react-components icon indicating copy to clipboard operation
obsidian-react-components copied to clipboard

react components plugin breaks obsidian new canvas feature box

Open mayankkalbhor opened this issue 2 years ago • 8 comments

Open new canvas. Click on drag to card. Observe it gives error "Error in comonent "const Headercomponent = plugininternalnoteheadercompnent

mayankkalbhor avatar Dec 23 '22 22:12 mayankkalbhor

Seems to be related to this renderer: https://github.com/elias-sundqvist/obsidian-react-components/blob/c90d943964d71287aca0eae990c5ced21d54cc76/src/header.tsx#L14

MeepTech avatar Jan 28 '23 19:01 MeepTech

I sadly can't get the plugin to build to provide a fix myself, but editing this line: https://github.com/elias-sundqvist/obsidian-react-components/blob/c90d943964d71287aca0eae990c5ced21d54cc76/src/header.tsx#L17

To this: https://github.com/MeepTech/obsidian-react-components-canvas-fix/blob/master/src/header.tsx#L17

Seems to fix it for me

(since i can't build it I edited it in the main.js file in the plugins folder manually as well to check)

MeepTech avatar Jan 28 '23 19:01 MeepTech

Where did you make this change @MeepTech I dont see this file. I only see main.js in my obsidian vault where i am using this plugin

mayankkalbhor avatar Mar 01 '23 15:03 mayankkalbhor

Where did you make this change @MeepTech I dont see this file. I only see main.js in my obsidian vault where i am using this plugin

@mayankkalbhor look for the registerHeaderProcessor function, and then inside that the call to registerMarkdownPostProcessor like in the code surrounding my change.

MeepTech avatar Mar 02 '23 19:03 MeepTech

@MeepTech The tsx file gets converted to js file and hence its not similar to what you have posted above. This is what i am seeing in main.js file in that portion that you suggested.

registerHeaderProcessor() {
    this.registerMarkdownPostProcessor((_, ctx) => __awaiter(this, void 0, void 0, function* () {
        var _a, _b;
        if (!((_a = ctx.containerEl) === null || _a === void 0 ? void 0 : _a.hasClass('markdown-preview-section'))) {
            return;
        }
        const viewContainer = ctx.containerEl.parentElement;
        const existingHeader = (_b = viewContainer === null || viewContainer === void 0 ? void 0 : viewContainer.getElementsByClassName('reactHeaderComponent')) === null || _b === void 0 ? void 0 : _b[0];
        const previousContext = this.renderedHeaderMap.get(existingHeader);
        if (!previousContext || previousContext != ctx) {
            if (existingHeader) {
                this.ReactDOM.unmountComponentAtNode(existingHeader);
                existingHeader.remove();
            }
            const container = document.createElement('div');
            container.addClasses(['reactHeaderComponent', 'markdown-preview-sizer', 'markdown-preview-section']);
            this.renderedHeaderMap.set(container, ctx);
            viewContainer === null || viewContainer === void 0 ? void 0 : viewContainer.insertBefore(container, ctx.containerEl);
            this.attachComponent('const HeaderComponent = pluginInternalNoteHeaderComponent; <HeaderComponent/>', container, ctx);
        }
    }));
}

Can you tell where i need to make this change now?

mayankkalbhor avatar Mar 02 '23 19:03 mayankkalbhor

Place it on a new line before var _a, _b; @mayankkalbhor

MeepTech avatar Mar 03 '23 15:03 MeepTech

@MeepTech Thanks for the help. I tested it working fine. Let me put in all my vaults. This is good workwround until fixed by the dev team.

mayankkalbhor avatar Mar 03 '23 17:03 mayankkalbhor

open main.js and do like this ... registerHeaderProcessor() { this.registerMarkdownPostProcessor((_, ctx) => __awaiter(this, void 0, void 0, function* () { if (!ctx.sourcePath || (!ctx.containerEl?.hasClass('markdown-preview-section'))) return; var _a, _b; if (!((_a = ctx.containerEl) === null || _a === void 0 ? void 0 : _a.hasClass('markdown-preview-section'))) { return; } ...

fireflysss avatar Sep 21 '23 11:09 fireflysss