Skip to content

feat(jsx): add useUnmount and useUpdateEffect hooks#628

Open
DarkSorcerer14 wants to merge 1 commit into
Karanjot786:mainfrom
DarkSorcerer14:feat/jsx-lifecycle-hooks
Open

feat(jsx): add useUnmount and useUpdateEffect hooks#628
DarkSorcerer14 wants to merge 1 commit into
Karanjot786:mainfrom
DarkSorcerer14:feat/jsx-lifecycle-hooks

Conversation

@DarkSorcerer14
Copy link
Copy Markdown

@DarkSorcerer14 DarkSorcerer14 commented Jun 3, 2026

Description

This PR implements the custom React-like lifecycle hook useUpdateEffect for the @termuijs/jsx package. It functions like standard useEffect but explicitly skips execution on initial render using a tracking useRef.

(Note: This PR originally included the implementation for #442 as well, but since #442 was prematurely closed via an unassigned PR, this now serves as the official completion for #443).

Related Issues

Closes #443

Verification Results

  • Automated Testing: Passed bun vitest run successfully with full unit test coverage.
  • Type Checking: Clean compilation via bun run typecheck across all monorepo scopes.

Summary by CodeRabbit

  • New Features

    • Introduced useUnmount hook for executing cleanup callbacks when components unmount
    • Introduced useUpdateEffect hook for running side effects on updates while skipping the initial render
  • Tests

    • Added comprehensive test suites for both new hooks

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5b850293-db9b-49b6-97c2-5ff50d7c54cf

📥 Commits

Reviewing files that changed from the base of the PR and between 1927797 and 0d8c8af.

📒 Files selected for processing (5)
  • packages/jsx/src/hooks/useUnmount.test.ts
  • packages/jsx/src/hooks/useUnmount.ts
  • packages/jsx/src/hooks/useUpdateEffect.test.ts
  • packages/jsx/src/hooks/useUpdateEffect.ts
  • packages/jsx/src/index.ts

📝 Walkthrough

Walkthrough

Two lifecycle hooks are added to the jsx package: useUnmount triggers a callback once on unmount, and useUpdateEffect mirrors useEffect but skips the first render. Both are implemented with complete test coverage and re-exported from the public API.

Changes

Lifecycle Hooks for JSX

Layer / File(s) Summary
useUnmount hook implementation and tests
packages/jsx/src/hooks/useUnmount.ts, packages/jsx/src/hooks/useUnmount.test.ts
useUnmount uses useEffect with an empty dependency array, returning the callback as the cleanup function to execute on unmount. Tests verify the callback does not run on mount or re-render, and runs exactly once when destroyFiber unmounts the component.
useUpdateEffect hook implementation and tests
packages/jsx/src/hooks/useUpdateEffect.ts, packages/jsx/src/hooks/useUpdateEffect.test.ts
useUpdateEffect skips the initial render using a useRef flag set after the first render, then delegates to useEffect for dependency handling. Tests confirm the effect skips on mount and unchanged dependencies, and runs with correct cleanup ordering when dependencies change.
Public API exports
packages/jsx/src/index.ts
Both useUnmount and useUpdateEffect are re-exported from the public API alongside existing hooks.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

Possibly related PRs

  • Karanjot786/TermUI#613: Overlapping useUnmount hook implementation, test coverage, and public API re-export changes.
  • Karanjot786/TermUI#572: Related to unmount lifecycle; modifies destroyFiber to run layout-effect cleanups, which directly affects useUnmount test assertions.

Suggested labels

type:feature, area:jsx, type:testing, level:beginner, quality:clean

Suggested reviewers

  • Karanjot786

Poem

🐰 Two hooks hop into the jsx hutch,
One to unmount with cleanup's touch,
One to skip the first render's dance,
They test and export—a perfect prance!
The fiber lifecycle's now complete,
These lifecycle tools are just too sweet! 🌿

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete relative to the provided template, missing several required sections like Which package(s), Type of Change checkboxes, Checklist items, and GSSoC 2026 participation. Fill out all required sections from the template including package name, type of change checkboxes, checklist verification items, and GSSoC profile information.
Out of Scope Changes check ❓ Inconclusive The PR includes both useUpdateEffect and useUnmount hooks, while the linked issue #443 only specifies useUpdateEffect; the useUnmount addition appears to be the out-of-scope implementation for issue #442. Clarify whether useUnmount implementation was intentional; if #442 is a separate objective, confirm its requirements are met or split into separate PRs.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and concisely summarizes the main changes: adding two custom hooks (useUnmount and useUpdateEffect) to the jsx package.
Linked Issues check ✅ Passed The PR implements useUpdateEffect per issue #443 requirements (hook signature, behavior, dependencies handling, tests, exports) and adds the useUnmount hook as a bonus.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feat/jsx-lifecycle-hooks

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added area:jsx @termuijs/jsx type:testing +10 pts. Tests. type:feature +10 pts. New feature. labels Jun 3, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

🎉 Thanks for your first PR to TermUI, @DarkSorcerer14.

Before your PR merges:

  1. Star the repo. Required. The star-check job blocks your merge otherwise.
  2. ✅ All checks green: build, test, typecheck.
  3. 🏷 PR title follows type: short description. Example: fix: handle empty list.
  4. 🔗 Link your closing issue in the description.

GSSoC 2026 points come from labels after merge:

  • gssoc:approved. +50 base points.
  • level:beginner / intermediate / advanced / critical. +20 / +35 / +55 / +80.
  • quality:clean / exceptional. x 1.2 / x 1.5.
  • type:*. Stackable bonus.

Your reviewer responds within 48 hours. Ping @Karanjot786 on Discord for urgent help.

🚀 Welcome to the cohort.

@DarkSorcerer14
Copy link
Copy Markdown
Author

Hi @Karanjot786 ! I've successfully implemented and fully verified useUpdateEffect with 0 type errors and passing unit tests. Looking forward to your review!

@shineetejol9
Copy link
Copy Markdown
Contributor

i'd like to work on this issue under gssoc 2026. please assign this to me

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

Labels

area:jsx @termuijs/jsx type:feature +10 pts. New feature. type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(jsx): add useUpdateEffect hook

2 participants