Skip to content

Fix useRefetchable/fromData incompatibility#634

Open
benjamin-thomas wants to merge 3 commits into
zth:masterfrom
benjamin-thomas:fix-from-data-compat-with-refetchable
Open

Fix useRefetchable/fromData incompatibility#634
benjamin-thomas wants to merge 3 commits into
zth:masterfrom
benjamin-thomas:fix-from-data-compat-with-refetchable

Conversation

@benjamin-thomas

Copy link
Copy Markdown

Hello!

#628 introduced fromData, but it appeared to be incompatible with the useRefetchableFragment hook.

This change short-circuits the hook, similar to what was done in useFragment already.

For the background info: I encountered this error while trying to render some components on a "storybook-like" page.

The runtime error looked something like this:

    Invariant Violation: Relay: Expected to receive an object where `...TestRefetching_user` was spread, but the fragment reference was 
not found`. This is most likely the result of:                                                                                          
    - Forgetting to spread `TestRefetching_user` in `useRefetchableFragment()`'s parent's fragment.
    - Conditionally fetching `TestRefetching_user` but unconditionally passing useRefetchableFragment() prop to `TestRefetching_user`. I
...

The failing test captures the error I encountered faithfully

@tsnobip tsnobip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

great fix @benjamin-thomas!

I'd just avoid using @obj and don't forget to update the CHANGELOG.md (add a # master section on top)

Comment thread packages/rescript-relay/src/RescriptRelay_Fragment.res Outdated
benjamin-thomas and others added 2 commits June 10, 2026 19:50
Co-authored-by: Paul Tsnobiladzé <paul.tsnobiladze@gmail.com>

@tsnobip tsnobip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM now!

@tsnobip tsnobip requested a review from zth June 11, 2026 09:01
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.

2 participants