Skip to content

Conversation

nikgraf
Copy link
Collaborator

@nikgraf nikgraf commented Jun 24, 2025

No description provided.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors how “space” context is provided and consumed across the codebase by introducing a streamlined HypergraphSpaceProvider and a new useSpace hook. It removes direct context coupling in entity hooks, centralizes subscription logic, and updates all routes and components to use the new API.

  • Add a space parameter to every query/entity hook and propagate it through useQueryLocal and useCreateEntity-style hooks
  • Simplify HypergraphSpaceContext to only hold a space ID and move handle subscription into useSubscribeToSpaceAndGetHandle
  • Update all React routes and components to use useSpace instead of manual subscribeToSpace calls and remove the old useHypergraphSpace

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/hypergraph/src/entity/findMany.ts Extracted FindManySubscription type and updated return type
packages/hypergraph-react/src/use-query.tsx Added space to QueryParams and passed it into useQueryLocal
packages/hypergraph-react/src/internal/use-query-public.tsx Switched to useHypergraphSpaceInternal for public queries
packages/hypergraph-react/src/index.ts Removed old useHypergraphSpace export in favor of useSpace
packages/hypergraph-react/src/HypergraphSpaceContext.tsx Overhauled provider and hook implementations to use new model
apps/events/src/routes/space/$spaceId/* Updated all page components to wrap in HypergraphSpaceProvider and drop manual subscriptions
apps/events/src/components/* Updated components to use useSpace and pass explicit space
Comments suppressed due to low confidence (1)

packages/hypergraph-react/src/use-query.tsx:12

  • You've added an optional space parameter here, but there are no unit tests verifying that overriding the context default works correctly. Consider adding tests for useQuery, useQueryLocal, and useCreateEntity when space is passed explicitly.
  space?: string;

Comment on lines 18 to 21
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
<HypergraphSpaceProvider space={spaceId}>
<SpaceChat spaceId={spaceId} />
</HypergraphSpaceProvider>
<SpaceChat spaceId={spaceId} />
</div>
);
Copy link

Copilot AI Jun 24, 2025

Choose a reason for hiding this comment

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

This page no longer wraps its children in HypergraphSpaceProvider, so calling useSpace inside SpaceChat will throw. Please wrap the returned JSX in <HypergraphSpaceProvider space={spaceId}>.

Copilot uses AI. Check for mistakes.

export function useUpdateEntity<const S extends Entity.AnyNoContext>(type: S) {
const hypergraph = useHypergraphSpaceInternal();
return Entity.update(hypergraph.handle, type);
export function useCreateEntity<const S extends Entity.AnyNoContext>(type: S, options?: { space?: string }) {
Copy link

Copilot AI Jun 24, 2025

Choose a reason for hiding this comment

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

[nitpick] useCreateEntity, useUpdateEntity, useDeleteEntity, etc. all share nearly identical handle-lookup logic. Consider extracting the shared subscription retrieval into a helper to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.

}, [spaceId, repo]);

const { subscribeToSpace, isConnecting } = useHypergraphApp();
useEffect(() => {
Copy link

Copilot AI Jun 24, 2025

Choose a reason for hiding this comment

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

The effect that calls subscribeToSpace does not store or call a cleanup/unsubscribe function. This could lead to repeated subscriptions if spaceId changes. Capture and call the unsubscribe function (if available) in the cleanup callback.

Copilot uses AI. Check for mistakes.

@nikgraf nikgraf merged commit 9c69ee7 into main Jun 24, 2025
6 checks passed
@nikgraf nikgraf deleted the ng/rework-space-context branch June 24, 2025 16:43
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