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

[BUG] ServerState should be reset on page navigation (sometimes) #331

Closed
jplhomer opened this issue Dec 6, 2021 · 1 comment · Fixed by #881 or #1106
Closed

[BUG] ServerState should be reset on page navigation (sometimes) #331

jplhomer opened this issue Dec 6, 2021 · 1 comment · Fixed by #881 or #1106
Assignees
Labels
bug Something isn't working framework Related to framework aspects of Hydrogen

Comments

@jplhomer
Copy link
Contributor

jplhomer commented Dec 6, 2021

Describe the bug
A user on Discord brought up an interesting issue when building pagination:

i tried to go off of the pagination implemented in the create-hydrogen-app and it seems that the numProducts state isn't being reset when switching between categories - thus resulting in loading numProducts + default number products on every category.
Is there a simple way to reset the server state if handle changes or something? not sure the "proper" way this could be achieved.

The problem here is that we use serverState for both routing and custom uses.

  • Routing uses pathname and search and is meant to be tied to a given route, fairly opaque to the developer, and persisted for new navigations
  • Custom state is whatever the developer decides to set, like pagination values. This should be cleared between page navigations
  • There is a third type of state, like a "permanent custom" state, which could serve as something that ought to remain for the duration of the browser session. Imagine a locale preference, a dark mode toggle, etc.

So perhaps to support this, we need to split serverState into two buckets: permanent and ephemeral? (but the API needs to not be named those gross things).

Is there another way to approach this?

@jplhomer jplhomer added the bug Something isn't working label Dec 6, 2021
@cartogram
Copy link
Contributor

Another potential API: We could start by changing the type of serverState from string to string | {value: string; permanent: boolean} where users can optionally specify the lifespan of the state (when to reset). It is a non-breaking change.

We should gather more use cases though, I'm not sure of how fine-grained control we need to expose. A more complex API could be a dependencies Array that tigger state refreshes.

@jplhomer jplhomer added the framework Related to framework aspects of Hydrogen label Feb 4, 2022
@jplhomer jplhomer self-assigned this Feb 4, 2022
@michenly michenly mentioned this issue Feb 7, 2022
4 tasks
rafaelstz pushed a commit to rafaelstz/hydrogen that referenced this issue Mar 4, 2023
Enter changesets pre-release mode: alpha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working framework Related to framework aspects of Hydrogen
Projects
None yet
2 participants