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

Add documentation for ref cleanup functions #6770

Merged
merged 2 commits into from
Apr 24, 2024

Conversation

jackpope
Copy link
Collaborator

No description provided.

Copy link

vercel bot commented Apr 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 24, 2024 4:44pm

Copy link

github-actions bot commented Apr 23, 2024

Size changes

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

jackpope added a commit to facebook/react that referenced this pull request Apr 23, 2024
Used this test scenario to clarify how callback refs work when detached
based on the availability of a cleanup function to update documentation
in reactjs/react.dev#6770

Checking it in for additional test coverage and test-based documentation
@jackpope jackpope requested a review from noahlemen April 23, 2024 17:44
Copy link
Collaborator

@noahlemen noahlemen left a comment

Choose a reason for hiding this comment

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

the content of this looks good to me overall, but considering versioning, maybe it would be best to update just the reference/ page, with all the changes within a CanaryBadge (that is, the information about cleanup functions / ref callbacks called with null would also be broken out to a canary badge)

then, after release, we'd update thelearn/ page as well? it seems like so far learn/ does not make reference to the canary, and that's probably not relevant information for that audience until a release.

@rickhanlonii
Copy link
Member

What I would do is inline the reference similar to useDeferredValue and either duplicate the examples with a note, or just defer the usage examples until 19 is released. Once it is released, we'll switch these docs fully to the new API.

@jackpope
Copy link
Collaborator Author

Updated reference changes to be inside a Canary UI block. Also reverted the null argument change in the list example, but kept the other changes since the old image service is broken and the updates make it easier for us to drop in the cleanup function usage later.

Copy link
Member

@rickhanlonii rickhanlonii left a comment

Choose a reason for hiding this comment

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

Looking good, left a couple nits

// Remove from the Map
map.delete(cat.id);
}
// Add to the map
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't indicate canary? I also don't understand why we'd need to add/remove cats?

Copy link
Member

Choose a reason for hiding this comment

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

For the Canary thing, I would keep the example the same and add a block.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah thanks I missed this spot. Updating to a Canary block.

For the add/remove, this was to make it more obvious how/when the cleanups are fired if you want to extend the example with logs or other behavior. Was helpful when putting it together but I'll update to simplify here.

@jackpope jackpope merged commit cdd2fdd into reactjs:main Apr 24, 2024
5 checks passed
Comment on lines -259 to +266
{catList.map(cat => (
{catList.map((cat) => (
<li
key={cat.id}
key={cat}
ref={(node) => {
const map = getMap();
if (node) {
map.set(cat.id, node);
map.set(cat, node);
} else {
map.delete(cat.id);
map.delete(cat);
}
}}
>
<img
src={cat.imageUrl}
alt={'Cat #' + cat.id}
/>
<img src={cat} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we leave all this as is? and keep the { id, imageUrl } structure in setupCatList? while this change is probably what i would prefer in actual code, i think the object makes things a bit more immediately grokkable in the context of examples

Copy link
Collaborator

Choose a reason for hiding this comment

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

whoops, didn't see you already merged. i don't feel strongly about this.

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

Successfully merging this pull request may close these issues.

4 participants