Skip to content

Commit 28e915d

Browse files
committed
Restore direct binding to solve Markdown editing issue
Revert part of 9f0632f
1 parent 8c2b74c commit 28e915d

4 files changed

Lines changed: 4 additions & 48 deletions

File tree

src/lib/components/contents/details/editor/field-editor.svelte

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import equal from 'fast-deep-equal';
55
import DOMPurify from 'isomorphic-dompurify';
66
import { marked } from 'marked';
7-
import { setContext, untrack } from 'svelte';
7+
import { setContext } from 'svelte';
88
import { writable } from 'svelte/store';
99
import { _ } from 'svelte-i18n';
1010
@@ -161,46 +161,6 @@
161161
widgetName === 'compute',
162162
);
163163
const invalid = $derived(validity?.valid === false);
164-
165-
/**
166-
* Store for the current value of the field. We use this to sync with the draft store because a
167-
* direct binding with `$entryDraft.currentValues[locale][keyPath]` degrades performance.
168-
* @type {any}
169-
*/
170-
let currentValueCache = $state();
171-
172-
/**
173-
* Timer for updating the draft store after a delay to avoid frequent updates while typing.
174-
* @type {number}
175-
*/
176-
let updateTimer = 0;
177-
178-
$effect(() => {
179-
if ($entryDraft) {
180-
const _currentValue = $entryDraft.currentValues[locale][keyPath];
181-
182-
untrack(() => {
183-
window.setTimeout(() => {
184-
if (currentValueCache !== _currentValue) {
185-
currentValueCache = _currentValue;
186-
}
187-
}, 0);
188-
});
189-
}
190-
});
191-
192-
$effect(() => {
193-
void currentValueCache;
194-
195-
untrack(() => {
196-
window.clearTimeout(updateTimer);
197-
updateTimer = window.setTimeout(() => {
198-
if ($entryDraft && $entryDraft.currentValues[locale][keyPath] !== currentValueCache) {
199-
$entryDraft.currentValues[locale][keyPath] = currentValueCache;
200-
}
201-
}, 200);
202-
});
203-
});
204164
</script>
205165
206166
{#if $entryDraft && canEdit && widgetName !== 'hidden'}
@@ -329,7 +289,7 @@
329289
{fieldId}
330290
{fieldLabel}
331291
{fieldConfig}
332-
bind:currentValue={currentValueCache}
292+
bind:currentValue={$entryDraft.currentValues[locale][keyPath]}
333293
{readonly}
334294
{required}
335295
{invalid}

src/lib/components/contents/details/toolbar.svelte

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
Toolbar,
1515
TruncatedText,
1616
} from '@sveltia/ui';
17-
import { sleep } from '@sveltia/utils/misc';
1817
import { _, locale as appLocale } from 'svelte-i18n';
1918
2019
import BackButton from '$lib/components/common/page-toolbar/back-button.svelte';
@@ -120,9 +119,6 @@
120119
return;
121120
}
122121
123-
// Wait a bit for updates in the field editor
124-
await sleep(250);
125-
126122
try {
127123
const savedEntry = await saveEntry({ skipCI });
128124

src/lib/components/contents/details/widgets/boolean/boolean-editor.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
let {
2222
/* eslint-disable prefer-const */
2323
fieldId,
24-
currentValue = $bindable(),
24+
currentValue = $bindable(false),
2525
required = true,
2626
readonly = false,
2727
invalid = false,

src/lib/components/contents/details/widgets/color/color-editor.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/* eslint-disable prefer-const */
2626
fieldId,
2727
fieldConfig,
28-
currentValue = $bindable(),
28+
currentValue = $bindable(''),
2929
required = true,
3030
readonly = false,
3131
invalid = false,

0 commit comments

Comments
 (0)