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: Don't notify changes for attributes not registered with the schema #9698

Merged
merged 7 commits into from
Feb 25, 2025

Conversation

gitKrystan
Copy link
Contributor

@gitKrystan gitKrystan commented Feb 24, 2025

Description

Fixes a bug where we would notify changes to data that wasn't actually registered with the schema. This seems to only cause issues if the data is coincidentally tracked for some other reason (e.g. id or a tracked property with the same name).

NOTE:
Currently (including with this change), we do not discard this data in the cache. So when you get the resource data out of the cache, we include it. Since some APIs are dependent on payloads being complete when you send them back, some users may rely on the current behavior. So we don't delete the value itself so that it's still merged in. We should probably deprecate this eventually.

Notes for the release

@gitKrystan gitKrystan added 🎯 canary PR is targeting canary (default) 🏷️ bug This PR primarily fixes a reported issue labels Feb 24, 2025
@gitKrystan gitKrystan changed the title Don't notify changes for attributes not registered with the schema fix: Don't notify changes for attributes not registered with the schema Feb 24, 2025
@@ -557,10 +557,12 @@ export default class JSONAPICache implements Cache {
this._capabilities.notifyChange(identifier, 'state', null);
}

const fields = this._capabilities.schema.fields(identifier);
Copy link
Contributor Author

@gitKrystan gitKrystan Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically I could only set this if one of the conditions below are met and we know we'll need it. Don't want to over-optimize

@@ -1740,7 +1740,7 @@ class Model extends EmberObject implements MinimalLegacyRecord {
this.eachComputedProperty((name, meta) => {
if (isAttributeSchema(meta)) {
assert(
"You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: attr('<type>')` from " +
"You may not set 'id' as an attribute on your model. Please remove any lines that look like: `id: attr('<type>')` from " +
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this error message match the other one so the tests don't care about where specifically the error is thrown.

test('_push does not require a modelName to resolve to a modelClass', function (assert) {
const store = this.owner.lookup('service:store');
const originalCall = store.modelFor;
store.modelFor = function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chris says we don't need this optimization anymore.

@gitKrystan gitKrystan merged commit ce1238c into main Feb 25, 2025
23 checks passed
@gitKrystan gitKrystan deleted the cache-key-filter branch February 25, 2025 23:58
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) 🏷️ bug This PR primarily fixes a reported issue
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants