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

Support history state that builds in stages #18

Closed
jakearchibald opened this issue Feb 2, 2021 · 2 comments
Closed

Support history state that builds in stages #18

jakearchibald opened this issue Feb 2, 2021 · 2 comments

Comments

@jakearchibald
Copy link

Imagine the following steps:

  1. User loads image from filesystem
  2. User selects codec
  3. User changes codec settings
  4. Repeat 3 a few times

If each of these was a history step, it either means storing the image from step 1 in each step, or determining current state from previous entries:

const combinedState = Object.assign(
  {},
  ...appHistory.entries
    .slice(0, appHistory.entries.indexOf(appHistory.currentEntry))
    .map((entry) => entry.state)
);

Storing the image in each step sounds bad for memory, especially if it's serialised in each entry.

Should getting the combinedState be made easier? Does this pattern result in lost data when pages are opened in a new window?

@domenic
Copy link
Collaborator

domenic commented Feb 2, 2021

I'm very interested in a solution to this problem, and in general to the question of how structured we should make app history state.

Some ideas:

  • Store the image separately somewhere (e.g., IDB, or some sort of session-IDB variant), and storing a pointer to the image in the history state. That feels kind of inconvenient; it'd be nice if history state could just be where everything goes.
  • Store the image in a format that is easily deduplicated by the browser. I think a Blob would suffice for this, or maybe an ImageBitmap. This relies a bit on browser magic though.
  • Have the app store the image in a particular canonical history entry, and retrieve it from there. Either using a generic pattern like you suggest, or using something more app-specific. (E.g. appHistory.entries.find(e => e.key === imageKey).)

Should getting the combinedState be made easier? Does this pattern result in lost data when pages are opened in a new window?

I think you should consider cases like this, similar to cases where the user sends the URL to their friend. If you want the data to be sharable, either on the same computer or across multiple computers, it should probably be in the URL. App history state (like history.state) works best as a session-specific cache for information that can be reconstructed or retrieved from the URL or other persistent information (such as a cookie).

I'm not confident on my thinking here, so pushback welcome.

/cc @tbondwilkinson

@domenic
Copy link
Collaborator

domenic commented Feb 3, 2021

Moved to WICG/navigation-api#17. (Unlike some other issue moves, I just quoted the conversation so far verbatim, as I feel like the problem is still very open.)

@domenic domenic closed this as completed Feb 3, 2021
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

No branches or pull requests

2 participants