Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/text editor/transclusion: fix an issue
Adorian Doran5d23d93d9df0
diff --git a/apps/client/src/widgets/type_widgets/text/TextEmbed.spec.tsx b/apps/client/src/widgets/type_widgets/text/TextEmbed.spec.tsxindex 2b1f239d86..875eb921da 100644--- a/apps/client/src/widgets/type_widgets/text/TextEmbed.spec.tsx+++ b/apps/client/src/widgets/type_widgets/text/TextEmbed.spec.tsx@@ -230,6 +230,15 @@ describe("TextEmbed", () => {.toBe("<div><p>Newer</p></div>");});+ it("shows a save that landed before it listened for saves", async () => {+ const note = buildTextNote("late");+ note.getBlob = async () => buildBlob("<p>Saved meanwhile</p>");+ const { figure } = await mount(note, buildEditor(), { content: "<p>Read before</p>" });+ await settle();+ expect(figure.querySelector(".editable-embed-preview")?.innerHTML)+ .toBe("<div><p>Saved meanwhile</p></div>");+ });+it("lets another include of the note follow its saves while an editor closes", async () => {const note = buildTextNote("shared");let finishSave = () => {};@@ -302,6 +311,8 @@ interface MountOptions {/** Whether the editor around the embed has a fixed toolbar, rather than a floating one. */hasFixedToolbar?: boolean;renderPreview?: (content: string) => Promise<HTMLElement>;+ /** The content that the host read for the embed, instead of the content of the note. */+ content?: string;}/** Renders `TextEmbed` in the markup of an embed, as the host does. */@@ -329,7 +340,7 @@ async function mount(note: FNote, editor: ContentEditor | undefined, options: Modocument.body.append(hostRoot);figures.push(figure);- const content = (await note.getBlob())?.content ?? "";+ const content = options.content ?? (await note.getBlob())?.content ?? "";await act(async () => {render(<ParentComponent.Provider value={appContext}>diff --git a/apps/client/src/widgets/type_widgets/text/TextEmbed.tsx b/apps/client/src/widgets/type_widgets/text/TextEmbed.tsxindex 1533795c4c..6030932f5d 100644--- a/apps/client/src/widgets/type_widgets/text/TextEmbed.tsx+++ b/apps/client/src/widgets/type_widgets/text/TextEmbed.tsx@@ -77,6 +77,10 @@ function useShownContent(note: FNote, initialContent: string) {}}, [ note ]);+ // Reads once on mount too, for a save that landed after the host read the content.+ useEffect(() => {+ void refresh();+ }, [ refresh ]);useTriliumEvent("entitiesReloaded", ({ loadResults }) => {if (loadResults.isNoteContentReloaded(note.noteId)) {void refresh();