Repository navigation
docs: add native DOM examples to Activity guide - #101581
Conversation
Tests PassedCommit: 450f4d1 |
|
All broken links are now fixed, thank you! |
| ```tsx highlight={3,7-9,20,25} | ||
| If a dialog should open when visiting a particular URL, derive its state from a search parameter. For example, this dialog opens when the URL includes `?edit=true`: | ||
|
|
||
| ```tsx highlight={7-9,15-17,28,33} |
There was a problem hiding this comment.
This highlights:
return (
<Suspense fallback={null}>
<ProductDialog />There was a problem hiding this comment.
great, i didnt reread the diff after having an agent try to build the examples. apparently it did a terrible job
| ``` | ||
|
|
||
| With this approach, `isDialogOpen` derives from the URL rather than component state. When navigating away and returning, the search param is cleared (the URL changed), so `isDialogOpen` becomes `false`. Opening the dialog sets the param, which changes `isDialogOpen` and triggers the Effect. | ||
| The [`Suspense` boundary](/docs/app/api-reference/functions/use-search-params#prerendering) lets the rest of the page prerender while the dialog reads the current search parameters. |
There was a problem hiding this comment.
Not correct anymore-ish... we can and should refactor so that the edit product button is a sibling to the boundary.
And, idk, this is not a Page or Layout, it is a contained piece of UI, who ever renders it could take care of the Suspense boundary placement. It depends.
| ``` | ||
|
|
||
| This resets all fields whenever the user navigates away. | ||
| Defining the callback outside the component keeps it stable across re-renders. `form.reset()` does not reset React state. For controlled inputs, reset the state passed to `value` or `checked`, as in the examples above. |
There was a problem hiding this comment.
Should we say why keep it stable? no?
| **When to keep it:** A sidebar with expanded sections, a FAQ accordion, or a filters panel. The user set up their view intentionally, and restoring it avoids re-doing that work. | ||
|
|
||
| **When to reset it:** A dropdown menu or popover triggered by a button click. These are transient interactions, not persistent view state. Returning to a page with a dropdown already open is not user friendly. | ||
| **When to reset it:** A dropdown menu or popover triggered by a button click, for example. These are transient interactions, not persistent view state. Returning to a page with a dropdown already open can be confusing. |
There was a problem hiding this comment.
maybe we keep the previous version? the , for example is odd, and calling it confusing mm perhaps
Summary
Adds the native popover example from #100208 to the existing Activity guide, with cleanup and unique IDs for elements in preserved pages. Also corrects the form-reset example to keep its callback ref stable across rerenders and distinguishes uncontrolled DOM values from controlled React state. Clarifies that an Effect running again does not necessarily mean a page was shown again, because Strict Mode also repeats setup and cleanup in development.
Verification
git diff --checkpass.