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

Production build crashes when trying to render a relation that is not present in the store #9038

Closed
azhiv opened this issue Oct 23, 2023 · 8 comments

Comments

@azhiv
Copy link
Contributor

azhiv commented Oct 23, 2023

Reproduction

A github repository with a simplified reproduction. Run ember serve -prod and check the error in the console.

Description

In case of a data issue a relation may point to a record with id that is not present in the store. In the development build this usually results in the following error:

Uncaught Error: Assertion Failed: You looked up the 'author' relationship on a 'book' with id don-juan but some of the associated records were not loaded. Either make sure...

In ED v3.28 the production build silently ignored this problem, essentially rendering an empty space in the template. However, in ED v4.12 (up to v5.3) this results in a very sophisticated exception:

Uncaught TypeError: Cannot read properties of undefined (reading 'localAttrs')...

originating from here.

This is very inconvenient because of two circumstances:

  1. The page crashes without allowing to interact with the UI.
  2. The exception conceals any details in order to cope with the data issue.

Versions

ember-data-missed-relation@0.0.0 /Users/artemz/src/ed-missed-relation
├─┬ @ember/test-helpers@3.2.0
│ └── ember-source@5.3.0 deduped
├─┬ ember-cli-app-version@6.0.1
│ └── ember-source@5.3.0 deduped
├─┬ ember-data@5.3.0
│ └─┬ @ember-data/model@5.3.0
│   └─┬ ember-cached-decorator-polyfill@1.0.2
│     └── ember-source@5.3.0 deduped
├─┬ ember-modifier@4.1.0
│ └── ember-source@5.3.0 deduped
├─┬ ember-qunit@8.0.1
│ └── ember-source@5.3.0 deduped
├─┬ ember-resolver@11.0.1
│ └── ember-source@5.3.0 deduped
└── ember-source@5.3.0

ember-data-missed-relation@0.0.0 /Users/artemz/src/ed-missed-relation
├─┬ ember-cli-dependency-checker@3.3.2
│ └── ember-cli@5.3.0 deduped
└── ember-cli@5.3.0

ember-data-missed-relation@0.0.0 /Users/artemz/src/ed-missed-relation
└── ember-data@5.3.0
@runspired
Copy link
Contributor

runspired commented Oct 23, 2023

this is likely the same issue as #8846 and it's unlikely we attempt to fix it as it represents the app doing incorrect things.

In older versions this led to the app displaying undefined emergent behaviors that were typically broken but did not immediately produce an error. For instance, by causing relationships to never update ever again once the issue occurred for them.

@azhiv
Copy link
Contributor Author

azhiv commented Oct 24, 2023

@runspired Since this is caused by a data issue on the BE we'd like to gain some details on what exactly is wrong in order to fix the inconsistencies. The problem here is that the exception raised on the FE doesn't provide any data-related information giving us no opportunity to react.

@runspired
Copy link
Contributor

@azhiv usually this means you are using a sync relationship but not loading the data for it in the initial payload (or in another sibling payload that resolves before first access of it).

Generally speaking if you want sync relationships that aren't sideloaded together with the primary data you're on the hook for extra work today to make things not blow up like this. Broad strokes, using links for relationships and creating a small wrapper to ensure fetch if needed from key points in your code will go pretty far.

@runspired
Copy link
Contributor

closing in favor of #9066 for tracking production asserts and #8846 for tracking for ensuring that if we do crash in this way that things are recoverable by the app if it catches the error and performs the right steps to address it

@enspandi
Copy link
Contributor

enspandi commented May 8, 2024

@runspired This issue was fixed with upgrading from 4.12.4 -> 4.12.5; But now we are on 5.3.3 and it appears again. Is this expected in v5?

@Baltazore
Copy link
Collaborator

@enspandi it might not hit stable release version of 5.3, can you try canary version ?
If it is working on canary - we will do release another stable minor shortly

@enspandi
Copy link
Contributor

enspandi commented May 8, 2024

@enspandi it might not hit stable release version of 5.3, can you try canary version ? If it is working on canary - we will do release another stable minor shortly

I tried with 5.4.0-alpha.61 but get same result unfortunately 🤔

chunk.b2c929b….js:389632 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'localAttrs')
    at JSONAPICache.getAttr (chunk.b2c929b….js:389632:16)
    at TicketLineItemModel.get (chunk.b2c929b….js:392369:89)
    at vendor.js:19273:25

@runspired
Copy link
Contributor

It looks like we never brought #9120 forward to the 5.x series, so we do need to do that.

This said: when you hit these issues it generally indicates something you want to refactor to stop doing 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

4 participants