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

Allow non-memoized item lists #4324

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

Conversation

ipc103
Copy link

@ipc103 ipc103 commented Feb 28, 2024

Closes #4315

CC @ajhenry

Changelog

Fixes a bug in the SelectPanel component which required the same object to be stored in the items and selectedItems lists.

New

N/A

Changed

Fixes a bug where SelectPanel wouldn't update state correctly when the items list contained different objects on re-render.

Removed

N/A

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

See the updated test cases for a minimal repro example.

Merge checklist

Towards primer#4315

The SelectPanel only did a basic equality check for the item state, meaning
that it depended on having the exact same objects on multiple pass throughs.

This isn't always possible as sometimes you may want to have different objects.

This replaces the equality check with a test for an `id` property on the object.

If the `id` property isn't present, we fallback to the old behavior.

Note that a previous version used the `key` prop, but we decided `id` was a
better interface. f472da2#r139163795
Co-authored-by: Andrew Henry <ajhenry@github.com>
@ipc103 ipc103 requested review from a team and siddharthkp February 28, 2024 19:06
Copy link

changeset-bot bot commented Feb 28, 2024

🦋 Changeset detected

Latest commit: b4253e9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Towards primer#4315

The SelectPanel only did a basic equality check for the item state, meaning
that it depended on having the exact same objects on multiple pass throughs.

This isn't always possible as sometimes you may want to have different objects.

This replaces the equality check with a test for an `id` property on the object.

If the `id` property isn't present, we fallback to the old behavior.

Note that a previous version used the `key` prop, but we decided `id` was a
better interface. f472da2#r139163795
Co-authored-by: Andrew Henry <ajhenry@github.com>
Comment on lines +130 to +132
if (selectedItem.hasOwnProperty('id')) {
return selectedItem.id === item.id
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should also try testing for key since that's React's way of differentiating component changes

Copy link
Author

Choose a reason for hiding this comment

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

I thought about that, but I actually think it's better to add the key when rendering over the list instead of trying to add it preemptively. Not super opinionated though if we want to use the key here!

@siddharthkp
Copy link
Member

Heads up: We can test if these changes are compatible with instances in gh/gh by creating an integration PR with this action: https://github.com/github/primer-engineering/blob/main/how-we-work/testing-primer-react-pr-at-dotcom.md

@siddharthkp
Copy link
Member

siddharthkp commented Feb 29, 2024

Followup: Here's the integration PR https://github.com/github/github/pull/314966

but I'm expected it to fail today (false negatives!!) because there are a couple unmerged fixes with gh/gh 😓 I'll update this PR once the fixes are merged

@ipc103
Copy link
Author

ipc103 commented Feb 29, 2024

Thanks @siddharthkp! Let me know if/how I can help.

@siddharthkp
Copy link
Member

Update: Here's the new integration PR: https://github.com/github/github/pull/315122

The CI is failing here. Is it because of the changes in this PR or unrelated? 🤔

@ipc103
Copy link
Author

ipc103 commented Mar 1, 2024

It does seem like some of those are related to this PR. I wonder if there are spots where we're working around the current behavior, or otherwise depending on it. I'll take a look and see if I can make this a non-breaking change!

@ipc103
Copy link
Author

ipc103 commented Mar 1, 2024

Looking more closely I'm not convinced those failures are related. They seem to be about unrelated components. I'm going to re-run just to make sure they aren't flakes or something.

@ajhenry
Copy link
Contributor

ajhenry commented Mar 5, 2024

Hey @siddharthkp anything we can help out with here? Looking through the test failures, it doesn't seem like this change should be involved but happy to debug where we can!

@siddharthkp
Copy link
Member

Hey @siddharthkp anything we can help out with here? Looking through the test failures, it doesn't seem like this change should be involved but happy to debug where we can!

Hey! sorry for the silence! Yeah, it's always tricky to tell when the integration tests have other errors as well 😢

If this is not urgent, I'm going to wait for the next release to go out so that I can have a clean slate to test this! Hope that's okay!

@ipc103
Copy link
Author

ipc103 commented Mar 22, 2024

Thanks @siddharthkp - that should work for us. The workaround is to just make sure that the list is memoized, so we can keep that up in the meantime.

Copy link
Contributor

Hi! This pull request has been marked as stale because it has been open with no activity for 60 days. You can comment on the pull request or remove the stale label to keep it open. If you do nothing, this pull request will be closed in 7 days.

@github-actions github-actions bot added the Stale label May 21, 2024
@ipc103
Copy link
Author

ipc103 commented May 22, 2024

@siddharthkp 👋 Hi! What do you think about this one - any chance we could cut another integration test branch and see if this change plays more nicely with the newer release?

@github-actions github-actions bot removed the Stale label May 22, 2024
@ipc103
Copy link
Author

ipc103 commented May 22, 2024

@siddharthkp I went ahead and created a new integration PR: https://github.com/github/github/pull/325842 I used the latest release candidate since it seems like canary builds are on pause at the moment. Did I do it right? If so, I think everything is passing 🤞

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.

SelectPanel should compare Objects based on key or id instead of the Objects themselves
3 participants