Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem using conditional fragments since v2+3 upgrade #99

Open
FINDarkside opened this issue Jun 25, 2024 · 2 comments
Open

Problem using conditional fragments since v2+3 upgrade #99

FINDarkside opened this issue Jun 25, 2024 · 2 comments

Comments

@FINDarkside
Copy link
Contributor

FINDarkside commented Jun 25, 2024

I'm unable to use conditional fragments where the fragment arguments come from url. This happened after updating from v1->v3 and I'm not quite sure how to fix this.

Here's a repro: https://github.com/FINDarkside/relay-nextjs-99-repro/blob/main/src/pages/relay-test.tsx
Here's the same thing in v1 where everything works: https://github.com/FINDarkside/relay-nextjs-99-repro/blob/v1/src/pages/relay-test.tsx

You can see that if you click the button you'll get this error: Invariant Violation: Relay: Expected to receive an object where `...AFragment` was spread, but the fragment reference was not found

@FINDarkside FINDarkside changed the title Issue with conditional fragments since v2 Invariant Violation when using conditional fragments based on query params Jun 25, 2024
@FINDarkside FINDarkside reopened this Jun 25, 2024
@FINDarkside FINDarkside changed the title Invariant Violation when using conditional fragments based on query params Problem using conditional fragments since v2+3 upgrade Jun 25, 2024
@rrdelaney
Copy link
Member

Hey @FINDarkside! Looks like the router and query vars are getting out of sync somehow. I recommend using the query variables for the source of truth, accessed from preloadedQuery.variables. I cloned your example and changed the following:

const isBEnabled = preloadedQuery.variables.includeB;

and that seemed to fix the issue!

@FINDarkside
Copy link
Contributor Author

Wow, I actually didn't even know we can access the variables and that they're also fully typed. That's going to come handy especially outside of this usecase. It also fixed the issue, big thanks for the help!

Regarding why this started breaking after update, I assume it means that previously after param change the page suspended immediately on the render, but doesn't do that anymore. It also means we now have to manually pass these variables down and render skeletons if the variable is false even though the component should be rendered. Previously we just relied on wrapping these components into Suspense and everything worked.

This isn't a blocker for me anymore thanks to your suggestion, but do you think I should keep this issue open or is this more like a feature than a bug?

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

No branches or pull requests

2 participants