Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to the Reactodia will be documented in this document.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
#### 🐛 Fixed
- Fix stale/non-saved data when calling `applyChanges()` immediately after `updateData()` in `EntityEditor` and `RelationEditor`.

## [0.34.0] - 2026-03-25
#### 🚀 New Features
Expand Down
4 changes: 3 additions & 1 deletion src/editor/dataLocaleProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ export class DefaultDataLocaleProvider implements DataLocaleProvider {
* }
* ```
*/
prepareAnchor(targetIri: string): Pick<React.ComponentProps<'a'>, 'href' | 'target' | 'rel' | 'onClick'> {
prepareAnchor(
targetIri: string
): Pick<React.ComponentProps<'a'>, 'draggable' | 'href' | 'target' | 'rel' | 'onClick'> {
return {
href: targetIri,
target: '_blank',
Expand Down
12 changes: 10 additions & 2 deletions src/widgets/editorForms/editEntityForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import cx from 'clsx';
import * as React from 'react';
import { flushSync } from 'react-dom';

import { useTranslation } from '../../coreUtils/i18n';
import { useAsync } from '../../coreUtils/hooks';
Expand Down Expand Up @@ -60,7 +61,7 @@ export function EntityEditor(props: {
/**
* Render function to make an editor UI using provided state.
*/
children: (props: EntityEditorProvidedProps) => React.ReactNode;
children: (props: EntityEditorProvidedProps) => React.ReactElement;
}) {
const {target, children} = props;
const {editor} = useWorkspace();
Expand All @@ -74,7 +75,14 @@ export function EntityEditor(props: {
data,
updateData: setData,
applyChanges: () => {
editor.changeEntity(target.data, data);
let finalData: ElementModel = data;
flushSync(() => {
setData(previous => {
finalData = previous;
return previous;
});
});
editor.changeEntity(target.data, finalData);
},
});
}
Expand Down
14 changes: 11 additions & 3 deletions src/widgets/editorForms/editRelationForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import cx from 'clsx';
import * as React from 'react';
import { flushSync } from 'react-dom';

import { useTranslation } from '../../coreUtils/i18n';
import { useAsync } from '../../coreUtils/hooks';
Expand Down Expand Up @@ -96,7 +97,7 @@ export function RelationEditor(props: {
/**
* Render function to make an editor UI using provided state.
*/
children: (props: RelationEditorProvidedProps) => React.ReactNode;
children: (props: RelationEditorProvidedProps) => React.ReactElement;
}) {
const {relation, onChangeTarget, children} = props;
const {model} = useWorkspace();
Expand Down Expand Up @@ -223,11 +224,18 @@ function RelationEditorInner(props: {
});
},
applyChanges: () => {
const toApply = dataFromExtendedLink(value.link);
let finalValue: ValidatedLink = value;
flushSync(() => {
setValue(previous => {
finalValue = previous;
return previous;
});
});
const toApply = dataFromExtendedLink(finalValue.link);

if (editor.temporaryState.links.has(original.data)) {
editor.removeTemporaryCells([original]);
const linkBase = relationFromExtendedLink(value.link, originalSource, originalTarget);
const linkBase = relationFromExtendedLink(finalValue.link, originalSource, originalTarget);
editor.createRelation(linkBase);
} else if (!(
equalLinks(original.data, toApply) &&
Expand Down
Loading