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

Ensure that field components do not get recreated when state changes #860

Merged
merged 6 commits into from
Nov 30, 2023

Conversation

jurgenwerk
Copy link
Contributor

@jurgenwerk jurgenwerk commented Nov 28, 2023

This is a result of pairing with @ef4 yesterday -

The issue we were solving is a bug where the "contains many" editor component will lose focus after inputting a single character, making it impossible to write a word in one go:

image

It turns out the whole editor component got replaced (i.e. we could see that the id in <div id="ember102"... got replaced) in DOM after state changes. The fix is that we now cache the components by field name, using the same technique we already use in getBoxComponent.

We were thinking about the possibilities about adding a test for this, but we don't actually know enough about the source of this problem. The described bug reproduction is one way to see the bug, but we assume that this is only one case among many, and that the glimmer engine is usually smart enough to not recreate components (but not in this case)...

@jurgenwerk jurgenwerk requested review from a team, ef4 and habdelra November 28, 2023 09:56
Copy link

github-actions bot commented Nov 28, 2023

Test Results

448 tests  +8   444 ✔️ +8   5m 14s ⏱️ -16s
    1 suites ±0       4 💤 ±0 
    1 files   ±0       0 ±0 

Results for commit e42dc22. ± Comparison against base commit 475c42e.

This pull request removes 2 and adds 10 tests. Note that renamed tests count towards both.
Chrome 119.0 ‑ Acceptance | code submode tests: displays clear message on inspector-panel and schema-editor when file is completely unsupported
Chrome 119.0 ‑ Acceptance | interact submode tests: card preview live updates when index changes
Chrome 119.0 ‑ Acceptance | code submode tests: card preview live updates when index changes
Chrome 119.0 ‑ Acceptance | code submode tests: displays clear message on schema-editor when file is completely unsupported
Chrome 119.0 ‑ Acceptance | code submode | create-file tests: can create a new card definition
Chrome 119.0 ‑ Acceptance | code submode | create-file tests: can create a new definition that extends card definition which uses default export
Chrome 119.0 ‑ Acceptance | code submode | create-file tests: can create a new field definition that extends field definition that uses default export
Chrome 119.0 ‑ Acceptance | code submode | create-file tests: can handle filename with .gts extension in filename when creating a new definition
Chrome 119.0 ‑ Acceptance | code submode | create-file tests: can handle leading "/" in filename when creating a new definition
Chrome 119.0 ‑ Acceptance | code submode | create-file tests: can sanitize display name when creating a new definition
Chrome 119.0 ‑ Acceptance | code submode | create-file tests: can specify new directory as part of filename when creating a new definition
Chrome 119.0 ‑ Acceptance | operator mode tests: can open code submode when card or field has no embedded template

♻️ This comment has been updated with latest results.

@jurgenwerk
Copy link
Contributor Author

Hm, looks like this breaks a couple of critical tests. I am not sure why the fields are not updating when assigning to the card instance programatically. I'm checking but have no good clue for now

Copy link
Contributor

@burieberry burieberry left a comment

Choose a reason for hiding this comment

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

Tested the ContainsMany input field and I can type! Looks good to me except the tests

@jurgenwerk jurgenwerk marked this pull request as draft November 28, 2023 22:15
@jurgenwerk jurgenwerk marked this pull request as ready for review November 30, 2023 09:25
@jurgenwerk
Copy link
Contributor Author

Ready for review - thanks @ef4 and @habdelra! It's great we have such good test coverage, they helped to uncover reactivity problems after addressing the caching problem.

@jurgenwerk jurgenwerk requested a review from a team November 30, 2023 09:27
Comment on lines +287 to +290
let getComponents = () =>
model.children.map((child) =>
getBoxComponent(cardTypeFor(field, child), format, child, field, context),
); // Wrap the the components in a function so that the template is reactive to changes in the model (this is essentially a helper)
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

Copy link
Contributor

@habdelra habdelra left a comment

Choose a reason for hiding this comment

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

looks great!

@jurgenwerk jurgenwerk merged commit 334789d into main Nov 30, 2023
@delete-merged-branch delete-merged-branch bot deleted the cs-6211-containsmany-editor-field-loses-focus branch November 30, 2023 23:43
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.

4 participants