Skip to content

fix linked cards occasionally missing. Use value.data.id #2430

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

tintinthong
Copy link
Contributor

@tintinthong tintinthong commented Apr 14, 2025

This PR is to fix the issue where linked data is missing

Screenshot 2025-04-09 at 23 40 10

Copy link

github-actions bot commented Apr 14, 2025

Host Test Results

  1 files  ±0    1 suites  ±0   29m 37s ⏱️ -58s
916 tests +7  910 ✅ +8  6 💤 ±0  0 ❌ ±0 
923 runs  +7  917 ✅ +9  6 💤 ±0  0 ❌  - 1 

Results for commit b097255. ± Comparison against base commit 04478cd.

This pull request removes 8 and adds 15 tests. Note that renamed tests count towards both.
Chrome ‑ Unit | identity-context garbage collection: a GC candidate is no longer considered a GC candidate if it is consumed by a subscriber
Chrome ‑ Unit | identity-context garbage collection: a GC candidate is no longer considered a GC candidate if it is consumed by an unsaved subscriber
Chrome ‑ Unit | identity-context garbage collection: a GC candidate remains a GC candidate if it is accessed via a set "null" in the identity map by local id
Chrome ‑ Unit | identity-context garbage collection: a GC candidate remains a GC candidate if it is accessed via a set "null" in the identity map by remote id
Chrome ‑ Unit | identity-context garbage collection: an instance becomes a GC candidate when it loses all subscribers
Chrome ‑ Unit | identity-context garbage collection: an instance becomes a GC candidate when it loses all unsaved subscribers
Chrome ‑ Unit | identity-context garbage collection: can mark unsaved instances without subscribers for GC
Chrome ‑ Unit | identity-context garbage collection: can mark unsubscribed instances that have been saved for GC
Chrome ‑ Acceptance | AI Assistant tests: cards are auto-attached in code mode
Chrome ‑ Integration | serialization > linksToMany: can resolve relative URLs in linksToMany fields irrespective of location of linked cards
Chrome ‑ Unit | identity-context garbage collection: a GC candidate is no longer considered a GC candidate if it is consumed by an instance that has a reference count > 0 
Chrome ‑ Unit | identity-context garbage collection: a GC candidate is no longer considered a GC candidate if it is consumed by an unsaved instance that has a reference count > 0
Chrome ‑ Unit | identity-context garbage collection: a GC candidate no longer remains a GC candidate if it accessed via setting a card error in the identity map
Chrome ‑ Unit | identity-context garbage collection: an instance becomes a GC candidate when its reference count drops to 0 for its remote id
Chrome ‑ Unit | identity-context garbage collection: an instance becomes a GC candidate when its reference count drops to zero for its local id
Chrome ‑ Unit | identity-context garbage collection: can add a card error to the identity map
Chrome ‑ Unit | identity-context garbage collection: can delete a card error from the identity map
Chrome ‑ Unit | identity-context garbage collection: can delete an instance from the identity map
…

♻️ This comment has been updated with latest results.

@tintinthong tintinthong force-pushed the fix-linked-cards-occasionally-not-rendering branch from 7df492d to 6a9c51d Compare April 14, 2025 13:36
@tintinthong tintinthong changed the title fix linked cards occasionally missing. Use value.data.id! fix linked cards occasionally missing. Use value.data.id Apr 14, 2025
@@ -966,7 +966,11 @@ class LinksTo<CardT extends CardDefConstructor> implements Field<CardT> {
cachedInstance[isSavedInstance] = true;
return cachedInstance as BaseInstanceType<CardT>;
}
let resourceId = new URL(value.links.self, relativeTo).href;
let relativeId =
value.data && Array.isArray(value.data)
Copy link
Contributor

@habdelra habdelra Apr 14, 2025

Choose a reason for hiding this comment

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

this is a LinksTo relationship, not a LinksToMany, why would the value here ever be an array? (keep in mind value here is the JSONAPI serialization for the relationship).

let relativeId =
value.data && Array.isArray(value.data)
? undefined // we don't know the id of the parent
: value.data?.id ?? relativeTo;
Copy link
Contributor

@habdelra habdelra Apr 14, 2025

Choose a reason for hiding this comment

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

generally we strive to serialize with the links.self when sending the serialized form of the instance to the server. both links.self and links.data.id are supported, using both though, can lead to the potential of conflicts if they were ever configured differently from each other. which is why we have opted to pick one (links.self is more concise). i'm super curious what the scenario is when you are deserializing a payload and links.data.id is populated and links.self is not. I think that is the actual bug if this is what is fixing it.

Copy link
Contributor

Choose a reason for hiding this comment

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

another thought is to remove links.self altogether and purely only use links.data.id (this this also means we should not serialize this so we don't introduce confusion).

Copy link
Contributor

@habdelra habdelra Apr 14, 2025

Choose a reason for hiding this comment

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

and another though is to favor links.self, but fallback to links.data.id if links self is not populated and links.data.id is populated. the drawback is that that gets into the confusing place of having these at odds with one another....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the input. The issue is really that value.links.self is relative. In addition, doc.data.id seems like the wrong id to be relative to anyway.

The data values are

value.links.self
../Category/someCategory

doc.data.id
http://test-realm/test/listing

value.data.id
http://test-realm/test/Category/someCategory

resourceId
http://test-realm/Category/someCategory

The expected value

resourceId
http://test-realm/test/Category/someCategory

I have added the serialization-test test "can resolve relative URLs in linksToMany fields irrespective of location of linked cards"

another thought is to remove links.self altogether and purely only use links.data.id (this this also means we should not serialize this so we don't introduce confusion).

I think value.data.id seems to return an absolute url which is actually what I want. Perhaps, this is what we want to do.

Copy link
Contributor Author

@tintinthong tintinthong Apr 15, 2025

Choose a reason for hiding this comment

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

Screenshot 2025-04-15 at 14 35 59

The JSON API docs consider data to be kinda optional actually. Tho it seems links.self are also treated as optional. I can see why implementation wise it can get unnecessarily complex

I think in deserialization we can prefer value.data.id but I think in general, if we fallback to links.self the deserialization may be wrong

removal of serialization however, lets talk about it perhaps after standup

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it’s especially tricky too, because I don’t think you can look at your contained card (or contained contained card, etc as the case may be), to see the id of the outermost document that you are relative too. That would be perfect if you could.

Copy link
Contributor

@habdelra habdelra Apr 15, 2025

Choose a reason for hiding this comment

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

Perhaps we need to thread thru a new parameter thru the deserialzation: the id of the document (if there is one), aka “relativeTo” so that we can resolve any relative hrefs. If we did that, there’s about 4-5 places that the relativeTo value would need to be added to function parameters.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you like maybe we can pair on this after standup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes pls that wud be helpful

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking one argument for not using links.data.id is that it makes it more challenging to copy a set of cards to a different realm. As relative references can be moved more easily.

@tintinthong tintinthong force-pushed the fix-linked-cards-occasionally-not-rendering branch from 6a9c51d to 844163d Compare April 15, 2025 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants