Skip to content

Conversation

@necolas
Copy link

@necolas necolas commented Jan 23, 2026

Description / Motivation

Consolidates the useFileTreeInstance mount/unmount and options change logic into a single ref callback, eliminating the need for the useStableCallback utility. Also removed the unused forceClientRender logic.

Typically we try to avoid useEffect, and anything tied to the lifecycle of a node is usually better done using a ref callback.

Changes:

  • Remove useStableCallback.ts utility (no longer needed)
  • Replace useStableCallback with useCallback that includes dependencies
  • Use React native ref callback cleanup (return cleanup function)
  • Remove unused forceClientRender prop and associated effect
  • Remove useIsometricEffect, useEffect, useLayoutEffect imports
  • Support both CSR and SSR modes by detecting prerendered content
  • Add CSR and SSR examples for Vanilla and React rendering

The ref callback now handles both lifecycle events by including options and prerenderedHTML in its dependency array. When these change, React calls the cleanup function then re-invokes the callback with the same DOM node, allowing detection and handling of options changes.

Example page changes:

  • Expanded from 2 to 4 examples: Vanilla CSR, Vanilla SSR, React CSR, React SSR
  • Use declarative shadow DOM () for Vanilla SSR
  • Add shared controls with startTransition for non-blocking updates.
  • Tests

    image

    Type of changes

    • Bug fix (non-breaking change which fixes an issue)
    • Refactoring (non-breaking change)
    • New feature (non-breaking change which adds functionality). You must have
      first discussed with the dev team and they should be aware that this PR is
      being opened
    • Breaking change (fix or feature that would change existing functionality).
      You must have first discussed with the dev team and they should be aware
      that this PR is being opened
    • Documentation update

    Checklist

    • I have read the
      contributing guidelines
    • My code follows the code style of the project (bun run lint)
    • My code is formatted properly (bun run format)
    • I have updated the documentation accordingly (if applicable)
    • I have added tests to cover my changes (if applicable)
    • All new and existing tests pass (bun run diffs:test)

    How was AI used in generating this PR

    • Claude Opus 4.5 + React Skills (local ones I wrote) were used to identify the avoidable effects.
    • Claude Opus 4.5 was used to generate the new examples

@vercel
Copy link

vercel bot commented Jan 23, 2026

@necolas is attempting to deploy a commit to the Pierre Computer Company Team on Vercel.

A member of the Team first needs to authorize it.

@necolas necolas changed the title File tree/react refs [file-tree] Refactor useFileTreeInstance use of refs Jan 23, 2026
@vercel
Copy link

vercel bot commented Jan 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
pierrejs-diff-demo Ready Ready Preview Jan 23, 2026 8:10am
pierrejs-docs Ready Ready Preview Jan 23, 2026 8:10am
pierrejs-solid-diff-demo Ready Ready Preview Jan 23, 2026 8:10am

Request Review

Consolidate mount/unmount and options change logic into a single ref
callback, eliminating useStableCallback utility and dead code.

Changes:
- Remove useStableCallback.ts utility (no longer needed)
- Replace useStableCallback with useCallback that includes dependencies
- Use React 19's native ref callback cleanup (return cleanup function)
- Remove unused forceClientRender prop and associated effect
- Remove useIsometricEffect, useEffect, useLayoutEffect imports
- Support both CSR and SSR modes by detecting prerendered content
- Add CSR and SSR examples for Vanilla and React rendering

The ref callback now handles both lifecycle events by including options
and prerenderedHTML in its dependency array. When these change, React
calls the cleanup function then re-invokes the callback with the same
DOM node, allowing detection and handling of options changes.

Example page changes:
- Add 4 examples: Vanilla CSR, Vanilla SSR, React CSR, React SSR
- Use declarative shadow DOM (<template shadowrootmode="open">) for SSR
- Add shared controls with startTransition for non-blocking updates
…ning

Include both flattened and non-flattened node IDs in expandedItems so the
folder stays expanded when toggling flattenEmptyDirectories. When flattened,
the node ID uses the 'f::' prefix; when not flattened, each intermediate
folder path is needed separately.

Added TODO noting the issue of not being able to specify file paths
directly and have the library compute the required IDs internally.
@necolas necolas force-pushed the file-tree/react-refs branch from 3058672 to b58836a Compare January 23, 2026 18:18
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.

1 participant