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

Rewrite provider #352

Merged
merged 11 commits into from
Dec 11, 2024
Merged

Rewrite provider #352

merged 11 commits into from
Dec 11, 2024

Conversation

paulgb
Copy link
Member

@paulgb paulgb commented Dec 10, 2024

This is essentially a complete rewrite of YSweetProvider. It incorporates the reconnect logic directly in the provider itself, instead of using the wrapper, which should make it easier to reason about. This paves the way to beginning to extend the protocol (as required for #306 and #308).

Copy link

vercel bot commented Dec 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
y-sweet-demos ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 11:19pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
y-sweet-debugger ⬜️ Ignored (Inspect) Visit Preview Dec 11, 2024 11:19pm
y-sweet-gendocs ⬜️ Ignored (Inspect) Visit Preview Dec 11, 2024 11:19pm

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to e28fca4 in 59 seconds

More details
  • Looked at 1199 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. js-pkg/client/src/main.ts:13
  • Draft comment:
    Update the JSDoc comment to reflect that createYjsProvider now returns a YSweetProvider instead of a Promise<YSweetProviderWithClientToken>.
  • Reason this comment was not posted:
    Comment was on unchanged code.
2. tests/src/index.test.ts:25
  • Draft comment:
    Consider re-adding the disableBc option to ensure tests run in isolated environments, as the removal might affect tests that rely on isolated environments for each provider instance.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The comment is speculative and does not provide strong evidence that the removal of disableBc will cause issues. It suggests a change without clear justification. According to the rules, speculative comments should be removed unless there is strong evidence of an issue.
    I might be overlooking the potential impact of removing disableBc on the test environment, but without strong evidence, the comment remains speculative.
    The rules prioritize strong evidence over speculation, so without clear evidence, the comment should be removed.
    The comment should be deleted because it is speculative and lacks strong evidence of an issue.
3. js-pkg/client/src/provider.ts:236
  • Draft comment:
    Ensure that closing the existing websocket before setting up a new one in bindWebsocket is the intended behavior and doesn't cause issues elsewhere in the application.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    In js-pkg/client/src/provider.ts, the bindWebsocket method is closing the existing websocket before setting up a new one. This is a good practice to ensure no lingering connections, but it should be confirmed that this behavior is intended and doesn't cause issues elsewhere.
4. js-pkg/react/src/main.tsx:67
  • Draft comment:
    Ensure that clientToken is always set when expected in useYSweetDebugUrl to prevent unexpected empty URL returns.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    In js-pkg/react/src/main.tsx, the useYSweetDebugUrl function checks for provider.clientToken before returning a URL. This is a good check to prevent errors, but it should be confirmed that clientToken is always set when expected.

Workflow ID: wflow_VK7ba20yFHDmQELd


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on f057dde in 8 seconds

More details
  • Looked at 24 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. debugger/src/app/debugger.tsx:28
  • Draft comment:
    Ensure that removing the WebSocket URL display does not affect debugging capabilities. Consider providing an alternative way to access this information if needed.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The removal of the WebSocket URL display might affect debugging capabilities. It's important to ensure that this information is not needed elsewhere or that there is an alternative way to access it if necessary.

Workflow ID: wflow_HbyJgZJHcYaYrkrc


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on d5c9923 in 8 seconds

More details
  • Looked at 40 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. js-pkg/client/src/provider.ts:65
  • Draft comment:
    The resyncInterval parameter was removed from YSweetProviderParams. Ensure that this removal does not affect any functionality that relied on this parameter.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The resyncInterval parameter was removed from the YSweetProviderParams type, but there is no indication of how this affects the functionality. If this parameter was used elsewhere, it might cause issues.

Workflow ID: wflow_7uJoGTnHGd9KWwqR


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Comment on lines 422 to 423
if (once) {
this.once(type, listener)
Copy link
Contributor

Choose a reason for hiding this comment

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

this.once calls this._on(type, listener, true) so I think this will recurse infinitely.

@jakelazaroff
Copy link
Contributor

(the nits aren't important but I think the this.once and constructor connect logic are both bugs)

@paulgb paulgb requested a review from jakelazaroff December 11, 2024 22:31
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 074f52b in 17 seconds

More details
  • Looked at 206 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_qUXWu6rDAmtXHJlv


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@jakelazaroff jakelazaroff left a comment

Choose a reason for hiding this comment

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

LGTM 🤘🏻

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on b04063f in 10 seconds

More details
  • Looked at 20 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. js-pkg/client/src/provider.ts:367
  • Draft comment:
    The emit function uses data: any = null, but YSweetEvent does not include null. Consider updating the type to include null or change the default value.
protected emit(eventName: YSweetEvent, data: any = undefined): void {
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The emit function uses a default parameter data: any = null, but the YSweetEvent type does not include null as a possible value. This could lead to type inconsistencies.

Workflow ID: wflow_OtZknozfWhh8dBN7


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@paulgb paulgb merged commit ecdb57b into main Dec 11, 2024
7 checks passed
@paulgb paulgb deleted the paul/dis-3018-rewrite-ysweetprovider branch December 11, 2024 23:25
paulgb added a commit that referenced this pull request Dec 12, 2024
`y-websocket` has a `synced` flag, but it is a bit misleading because it
only tells whether the initial handshake was completed. Knowing whether
a document was synced _in general_ for `y-protocols` is a bit tricky,
because we would need to compare the state vector and delete set.

When using WebSockets, we can take advantage of the ordering guarantee
and synchronous message processing in Y-Sweet to implement a very simple
check of sync.

The client stores two numbers, `lastSyncSent` and `lastSyncAcked`. When
it sends an update to the server, it also increments `lastSyncSent` and
then sends a separate `messageSyncStatus` message containing that number
as the payload.

When the server receives a `messageSyncStatus`, it simply echoes it
verbatim. When the client receives the `messageSyncStatus` in return, it
updates `lastSyncAcked` to the payload of the message.

If `lastSyncAcked` = `lastSyncSent`, we know that all messages since the
last update have been processed. Otherwise, there are outstanding
changes.

This builds on #352 and will enable #306.

Demo:


https://github.com/user-attachments/assets/60d4aec2-f025-4e84-a594-28fbc84c67cb
paulgb added a commit that referenced this pull request Dec 16, 2024
This builds on top of #352 to add offline support to the Y-Sweet
provider. It's also exposed through the React bindings by passing
`enableOfflineSupport={false,true}` to `YDocProvider`.

The approach is similar to `y-indexeddb`, where updates are stored
incrementally and then compacted when the set of updates gets large.

Browsers generally store indexeddb in plain text on disk. We encrypt the
data using `AES-GCM`, and store the key in a cookie. Since cookies often
store credentials, they are often treated more sensitively than local
storage (Chrome encrypts them on disk, and stores the decryption key in
the OS's keychain; Firefox and Safari still use plaintext.)

Each document gets its own "database" in indexeddb, but the key is
shared across the origin.

Since multiple tabs can have the same document open, they attempt to
coordinate:
- Before writing to the database, we attempt to fetch any updates we
haven't seen and apply them
- When a client updates, it broadcasts a message telling other clients
to update
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