Skip to content

Fix useRefetchable/fromData incompatibility#634

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

Fix useRefetchable/fromData incompatibility#634
benjamin-thomas wants to merge 4 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

@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
@benjamin-thomas benjamin-thomas force-pushed the fix-from-data-compat-with-refetchable branch from fd9fe3a to bb5d095 Compare June 23, 2026 16:31
@benjamin-thomas

Copy link
Copy Markdown
Author

Just a heads up, I added another commit to handle the pagination hook.

Let's say you want to demonstrate a component that requires pagination, this resulted in a runtime error. I applied the same solution as before : detect if we have test data from fromData and NOOP, otherwise behave as before.

There's probably at least one or a few hooks that could receive the same treatment but I'm only concerned with those two at the moment.

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