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

ember 5.6+ causes tracking issues #110

Open
Techn1x opened this issue Aug 29, 2024 · 9 comments · Fixed by #111
Open

ember 5.6+ causes tracking issues #110

Techn1x opened this issue Aug 29, 2024 · 9 comments · Fixed by #111

Comments

@Techn1x
Copy link
Contributor

Techn1x commented Aug 29, 2024

Hello!

I recently started hitting some strange tracking issues with a combination of trackedFunctions and getters. The behaviour I noticed was;

  • a trackedFunction would return a new value, but a getter consuming that wouldn't update (that getter is referenced by another TrackedFunction, which is referenced by another getter, which is then used in a template)
  • bug only occurred in local / dev builds, but was fine in production builds
  • only occurs from ember 5.6+

This gives an idea of what I have. The example is contrived but it represents how my code is structured

abc = trackedFunction(this, async () => {
  const items = await getItems()
  return items
})

// this correctly returns "undefined" while abc is pending, but never runs again when abc is done
get firstItem() {
  return this.abc.value?.[0]
}

// this receives the firstItem "undefined" but never updates
def = trackedFunction(this, async () => {
  if (!this.firstItem) return []
  const manifestBundle = await fetchForItem(this.firstItem)
  return manifestBundle
})

get currentManifestBundle() {
  return this.def.value ?? []
}
{{#each this.currentManifestBundle as |manifest|}}
  ...
{{/each}}

From what I can tell, it is to do with ember-source - 5.4.1 works, 5.6 does not (nor does 5.8).
I've put together this failing PR that might help #109

@Techn1x
Copy link
Contributor Author

Techn1x commented Aug 30, 2024

Oh I see the tests are passing on ember 5.8 now! nice. I will consume next update when published and see if my issue is resolved, otherwise I'll write up a failing test that targets the behaviour I am seeing. Thanks!

@NullVoxPopuli
Copy link
Contributor

Gonna re-open this as I didn't actually debug it, and the 5.6 to 5.8 changes shouldn't be affectiing reactiveweb -- however -- the VM did get upgraded in 5.6, and reactivity did get more strict about what you're allowed to do.

// this correctly returns "undefined" while abc is pending, but never runs again when abc is done

what updates abc?

@NullVoxPopuli NullVoxPopuli reopened this Aug 30, 2024
@Techn1x
Copy link
Contributor Author

Techn1x commented Sep 3, 2024

These are all wrapped in a class, I set something in a constructor. Wonder if that's got something to do with it?

class LessonActivity {
  lesson: number
  
  constructor(lesson: number) {
    // setOwner(...) etc
    this.lesson = lesson
  }

  abc = trackedFunction(this, async () => {
    const items = await getItems(this.lesson)
  ...
}

and the template would look something like this

openLesson = () => {
  this.lessonActivity = new LessonActivity(1)
}

<template>
  ...
  {{each this.lessonActivity.currentManifestBundle as ||}}
    ...
</template>

@NullVoxPopuli
Copy link
Contributor

Is lesson activity tracked?

@Techn1x
Copy link
Contributor Author

Techn1x commented Sep 3, 2024

Yeah it is. I can try to create a failing test if nothing obvious is coming to mind

@NullVoxPopuli
Copy link
Contributor

Yeah, nothing obvious is jumping out at me.

A failing test pr would be wonderful!

@Techn1x
Copy link
Contributor Author

Techn1x commented Sep 13, 2024

Put together this test case which closely matches what I am aiming to do, though it is succeeding 😅 #115

Back to the drawing board. I'm going to try copying that test case over into my application and see if it fails/succeeds there under ember 5.8

@NullVoxPopuli
Copy link
Contributor

thanks for your efforts!!!

@Techn1x
Copy link
Contributor Author

Techn1x commented Sep 16, 2024

Managed to get the test to fail! Commented on that failing test PR, it's something to do with modifiers consuming the tracked-function before other things.

Techn1x added a commit to Techn1x/reactiveweb that referenced this issue Sep 17, 2024
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 a pull request may close this issue.

2 participants