fix error with circular reactivity

This commit is contained in:
Chris Kruining 2025-03-05 15:48:21 +01:00
parent 6a64612537
commit 7cdefe3f6e
No known key found for this signature in database
GPG key ID: EB894A3560CCCAD2
2 changed files with 31 additions and 17 deletions

View file

@ -1,4 +1,4 @@
import { Component, createEffect, createMemo, createSignal, For, onMount, untrack } from 'solid-js';
import { Component, createEffect, createMemo, createSignal, For, on, onMount, untrack } from 'solid-js';
import { debounce } from '@solid-primitives/scheduled';
import { createSelection, getTextNodes } from '@solid-primitives/selection';
import { createSource } from '~/features/source';
@ -18,12 +18,21 @@ interface TextareaProps {
export function Textarea(props: TextareaProps) {
const [selection, setSelection] = createSelection();
const [editorRef, setEditorRef] = createSignal<HTMLElement>();
let mounted = false;
const source = createSource(props.value);
createEffect(() => {
props.oninput?.(source.in);
});
createEffect(on(() => [props.oninput, source.in] as const, ([oninput, text]) => {
if (!mounted) {
return;
}
oninput?.(text);
}));
onMount((() => {
mounted = true;
}));
createEffect(() => {
source.in = props.value;
@ -109,13 +118,19 @@ const Suggestions: Component = () => {
const ref = untrack(() => suggestionRef()!);
if (m === undefined) {
ref.hidePopover();
if (ref.matches(':popover-open')) {
ref.hidePopover();
}
return;
}
m.style.setProperty('anchor-name', '--suggestions');
ref.showPopover();
if (ref.matches(':not(:popover-open)')) {
ref.showPopover();
}
ref.focus()
return m;