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

fix: restore old behavior in deprecation #9364

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

enspandi
Copy link
Contributor

Description

This is a fix for the deprecation @ https://deprecations.emberjs.com/ember-data/v5.x/#toc_ember-data-deprecate-relationship-remote-update-clearing-local-state

In the case of a remote update with a local change, I think we want to have the remote state as the local state in the old way.

@runspired Does this make sense? Just encountered this issue in our upgrade from v4 => v5. Perhaps this is a copy/paste issue from the deprecation warning in line #89...


In v4 we run into this branch:

https://github.com/emberjs/data/blob/v4.12.7/packages/graph/src/-private/graph/operations/replace-related-record.ts#L131

if (localState !== remoteState) {
  relationship.localState = remoteState;

In v5 we run into this branch:

if (localState !== remoteState && localState === existingState) { // <-- Does not apply as we have a local mutation
  relationship.localState = remoteState;
  notifyChange(graph, relationship.identifier, relationship.definition.key);
} else if (DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE) {
  if (
    localState !== remoteState &&
    localState !== existingState &&
    relationship.definition.resetOnRemoteUpdate !== false
  ) {
    relationship.localState = existingState; // <-- Should be remoteState?

https://github.com/emberjs/data/blob/v5.3.3/packages/graph/src/-private/operations/replace-related-record.ts#L168


Example:

We change a relationship from record "1" to "null" and on save, the server returns a record "99" for this relationship.

In v4 and v5 we have the following state:

// Before the local change it was '1'
existingState.id; // = '1';

// Local change clears the relationship
relationship.localState; // = null;

// Remote wants to set '99'
op.value.id; // '99'

In v4 we end up with '99' as the new local state (relationship.localState = remoteState).

In v5 we end up with '1' as the new local state (relationship.localState = existingState). But in my understanding it should be '99' in the old way.

Notes for the release

@runspired
Copy link
Contributor

This feels like a variant of #9263 and is probably a correct fix

@runspired runspired added 🎯 release PR should be backported to release 🎯 canary PR is targeting canary (default) 🎯 lts The PR should be backported to the most recent LTS 🏷️ bug This PR primarily fixes a reported issue labels Apr 18, 2024
@runspired runspired merged commit 6f0889c into emberjs:main Apr 18, 2024
25 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎯 canary PR is targeting canary (default) 🎯 lts The PR should be backported to the most recent LTS 🎯 release PR should be backported to release 🏷️ bug This PR primarily fixes a reported issue
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants