Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit Tree Node -> Title Lags Behind Field Value #3579

Open
carlosmbe opened this issue Jun 6, 2023 · 6 comments
Open

Edit Tree Node -> Title Lags Behind Field Value #3579

carlosmbe opened this issue Jun 6, 2023 · 6 comments
Labels
1 - Bug Incorrect behavior of the product

Comments

@carlosmbe
Copy link
Contributor

Describe the bug
The Title in the Editor lags a single character behind the actual field when being changed

To Reproduce
Steps to reproduce the behavior:

  1. Go to any tree node and click edit
  2. Delete a character or a few from Name and see observe the title reacts
  3. See error

Expected behavior
Would be great if they were in sync

Screen Recording

Smaller.Type.Lag.mp4

Desktop:

  • OS: Mac OSx Ventura
  • Browser: Chrome
  • Specify 7 Version: 7.8.11 and 7.8.12
@carlosmbe carlosmbe added 1 - Bug Incorrect behavior of the product pri:unknown labels Jun 6, 2023
@melton-jason
Copy link
Contributor

I believe this has been an issue for quite some time (though I can't find an issue for it, if one existed).
Note that if you make any changes to the Form (not just name), the Dialog title gets updated.

@maxpatiiuk
Copy link
Member

Likely will be fixed by migrating off backbone

@melton-jason
Copy link
Contributor

I believe the issue is regarding BackBone events.
(Correct me if I'm wrong) We currently rely on BackBone events to monitor and perform callbacks when an event is triggered.
However, even when used in a useEffect() or similar hook, either the change to the resource happens after the re-render is triggered, or some BackBone's implementation of events does not work well with React hooks.

@maxpatiiuk
Copy link
Member

I think the issue is that we don't have a useEffect() at all in this place and are using resource.get('') directly inside of component render (I might be wrong, I didn't look at the code) - which is intuitive, but causes a bug.

rather than fixing this place (and many more places that have a similar issue), we should just migrate to a new resource ORM, where resource changes trigger react re-render

@melton-jason
Copy link
Contributor

Ah, I see now (maybe)!
For the ResourceView, we are getting the title from the useResourceView hook.
There is a useEffect() in the hook, but not on the Resource View component.
I'm assuming the 'fix' for this would be to create a useEffect() hook in ResourceView that forces a re-render when the 'title' value from the useResourceView hook changes. Although it does seem slightly redundant, it makes sense if this is the case 😅

const {
formElement,
formPreferences,
form,
title,
formatted,
jsxFormatted,
specifyNetworkBadge,
} = useResourceView({
isLoading,
isSubForm,
mode,
resource,
viewName,
});

const [formatted, setFormatted] = React.useState<LocalizedString>('');
React.useEffect(() => {
setFormatted(resource?.specifyModel.label ?? commonText.loading());
return typeof resource === 'object'
? resourceOn(
resource,
'change',
(): void => {
if (resource === undefined) return undefined;
format(resource)
.then((title) => {
setFormatted(title ?? '');
return undefined;
})
.catch(softFail);
},
true
)
: undefined;
}, [resource]);

@emenslin
Copy link
Collaborator

emenslin commented Aug 5, 2024

Can recreate in edge (7.9.6)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - Bug Incorrect behavior of the product
Projects
None yet
Development

No branches or pull requests

5 participants