feat(modal): imperative store API + transition/collapse animation fixes#135
Merged
wangdicoder merged 2 commits intomasterfrom Apr 27, 2026
Merged
feat(modal): imperative store API + transition/collapse animation fixes#135wangdicoder merged 2 commits intomasterfrom
wangdicoder merged 2 commits intomasterfrom
Conversation
Modal: - Replace the reducer-based context with a `ModalStore` external store (subscribe / show / hide / hideAll / register / remove). `show(id, props)` returns a promise resolved by `hide(result)`. - Add `Modal.Register`, `Modal.useModalActions`, `Modal.useModalSelf`, `Modal.store`, and a named `createModalStore` factory; legacy `Modal.useModal(id)` continues to work unchanged. - Re-export `createModalStore` from `@tiny-design/react`. - Add tests covering the per-id hook, registered components with awaitable results, declarative `<Modal.Register>` (incl. unmount), `hideAll`, `remove()` draining a pending resolver, and the `useModalSelf` outlet guard. - Refresh demos: Context (manual mount via `useModalActions`) and a new ContextRegister demo (registered + awaitable result). Document the Context API and a "Choosing a store" section in EN/ZH docs. Transition: - Move `onExited` side effect out of the `setState` updater (use a stateRef for race protection). Avoids "Cannot update X while rendering Y" warnings when `afterClose` dispatches across components. Collapse: - Always mount `<CollapseTransition>`; gate only the inner body content. The first time a panel expands from a closed start now plays the open animation instead of snapping to full height. CollapseTransition: - Keep `onHidden` in a ref so the animation effect depends only on `visible`. Inline `onHidden` callers no longer have unrelated parent re-renders interrupt the running animation. Docs: - Make markdown-tag's `slugifyLink` handle React node children so headings with inline `<code>` (e.g. `### \`ModalStore\``) don't crash.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
show(id, props)returns a promise resolved byhide(result), with newModal.Register,Modal.useModalActions,Modal.useModalSelf,Modal.store, and a namedcreateModalStorefactory. The legacyModal.useModal(id)per-id hook is unchanged.fix(transition):moveonExitedside effect out of asetStateupdater (uses astateReffor race protection). Eliminates "Cannot update component X while rendering Y" warnings whenafterClosedispatches across components.fix(collapse):always mount<CollapseTransition>; the first time a panel expands from a closed start now animates instead of snapping open.fix(collapse-transition):stashonHiddenin a ref so the animation effect depends only onvisible. Unrelated parent re-renders no longer interrupt the running open/close animation (e.g. clicking Delete in the Deletable demo while another panel is animating).fix(docs):slugifyLinknow extracts text from arbitrary React-node heading children, so MDX headings with inline<code>no longer crash the docs renderer.Release
@tiny-design/react: minor — adds new public API. ExistingModal.useModal(id)/<Modal.Provider>/Modal.open/Modal.confirmcallers continue to work without changes.Test plan
pnpm --filter @tiny-design/react test(817 tests, 99 suites) greenpnpm dev):