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

Update state management to use Universal ID #120

Merged
merged 24 commits into from
Feb 13, 2024
Merged

Update state management to use Universal ID #120

merged 24 commits into from
Feb 13, 2024

Conversation

hopsoft
Copy link
Owner

@hopsoft hopsoft commented Feb 10, 2024

Reduce potential ISP/Gateway privacy concerns related to user tracking etc.

Note

There aren't any inherent privacy issues related to TurboBoost Commands (TBC). TBC does NOT track user/visitor data for any purpose. The original cookie and header management simply served to facilitate a better user experience (UX).

This PR updates the "state" mechanics to use the URL and hidden form fields rather than cookies and headers for this purpose.

TurboBoost state management provides a facility for remembering and restoring the state used to render the last representation of a page or component. It also provides the facility to support client side optimistic updates that we can resolve server side. All of this tooling enables developers to provide a great reactive user experience to visitors with minimal code.


After more discovery and some conversations with AI, I've teased out the following areas that are potential spots that may can appear suspect to naive privacy tools.

  • Storing larger values in cookies
  • Using too many cookies
  • Attaching larger values to HTML request headers
  • Using too many custom request headers
  • Updating or mutating an HTML meta tag too frequently

This PR addresses each of the above items to de-risk privacy hawks from attaching a false positive flag due to any library activity or operations.

@hopsoft hopsoft marked this pull request as ready for review February 10, 2024 20:35
// always send state
state.payloadChunks.forEach((chunk, i) => {
fetchOptions.headers[`TurboBoost-State-${i.toString().padStart(4, '0')}`] = chunk
})
Copy link
Owner Author

@hopsoft hopsoft Feb 12, 2024

Choose a reason for hiding this comment

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

Previously we always sent state. We may want to consider bringing this back when we put more attention on state management and optimistic updates. I think it's fine to omit for now.

Copy link
Contributor

@mhenrixon mhenrixon left a comment

Choose a reason for hiding this comment

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

As I wrote you in our private conversation, my only problem seems to be with elements that could be expected with such a refactoring.

Commands seems to be working great for me (I use that individually for some really cool stuff as well).

My PRs should help simplify the setup for testing import maps, but I see nothing obvious in this PR, nor do I have any issues other than with elements.

It's good to go unless you depend on elements being fixed first.

app/javascript/index.js Show resolved Hide resolved
app/javascript/index.js Show resolved Hide resolved
pin "debounced", to: "https://ga.jspm.io/npm:debounced@0.0.5/src/index.js"
# TODO: I have no idea why the fuck jspm.io refuses to build the latest versions of @turbo-boost libs
# You can generate URLs like the one I'm using below here → https://www.jsdelivr.com/github
pin "@turbo-boost/streams", to: "https://cdn.jsdelivr.net/gh/hopsoft/turbo_boost-streams@v0.1.6/app/assets/builds/%40turbo-boost/streams.js"
Copy link
Contributor

Choose a reason for hiding this comment

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

After merging my PR, you should be able to use:

pin "@turbo-boost/streams", to: "@turbo-boost/streams.js"

lib/turbo_boost/commands/runner.rb Show resolved Hide resolved
lib/turbo_boost/commands/state.rb Show resolved Hide resolved
lib/turbo_boost/commands/state.rb Outdated Show resolved Hide resolved
def append_meta_tag_to_response_body
cookies.encrypted["turbo_boost.token"] = {value: new_token, path: "/"}
append_to_response_body turbo_stream.invoke("morph", args: [meta_tag], selector: "#turbo-boost")
def append_command_token_to_response_body
Copy link
Collaborator

Choose a reason for hiding this comment

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

This method name had me dig into the source as to what is actually appended where. 👇 makes total sense, but from the method name I'd have assumed it's inserting it as a text node or something.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Perhaps we can follow up with more clear semantic naming for some of these.

test/state_test.rb Outdated Show resolved Hide resolved
test/state_test.rb Outdated Show resolved Hide resolved
test/state_test.rb Outdated Show resolved Hide resolved
Copy link

@BuddyLReno BuddyLReno left a comment

Choose a reason for hiding this comment

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

I don't have enough context to offer any meaningful feedback but I didn't see any obvious logic errors or typos 👍

@hopsoft hopsoft merged commit 5c065fd into main Feb 13, 2024
9 checks passed
@hopsoft hopsoft deleted the hopsoft/uid branch February 13, 2024 02:32
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.

4 participants