Skip to content

Fix typed text never reaching shared drafts - #3

Merged
lsegal merged 3 commits into
mainfrom
fix/issue-1-share-sync
Oct 3, 2026
Merged

lsegal merged 3 commits into
mainfrom
fix/issue-1-share-sync

Conversation

@lsegal

@lsegal lsegal commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Typing in a shared draft never reached the other browser, in either direction.

Root cause

The screenplay page is one contentEditable host (.screenplay-editable), and the paragraphs inside it are plain children. Browsers send input events to the editing host, not to the paragraph being typed in, so the per-paragraph onInput handler never ran. Typed characters stayed in the DOM and were only written to the Yjs document when a key handler happened to capture the paragraph text (Enter, Tab, Delete…). Nothing reached the shared doc, so y-webrtc had nothing to send. As a side effect, plain typing was also lost on reload.

I reproduced this with two isolated Chrome contexts against this repo's own signaling worker (wrangler dev). The peers connected ("2 in room") and the initial document state synced, but typed text never reached the other side, or even the local Yjs doc.

Change

  • Handle input on the .screenplay-editable host, resolve the edited paragraph from the event target or selection (shared with the existing keydown lookup), and call project.updateParagraph. Removed the dead per-paragraph onInput.
  • Record the caret offset before the update so the existing pendingCaret layout effect puts it back after React re-renders the paragraph text. Without this, each keystroke would reset the caret to the start.

Verification

  • New app/src/App.test.tsx: mounts the editor, sends an input event to the editing host the way a browser does, reopens the draft from IndexedDB, and checks that the text persisted. It fails on main (expected [ '' ] to include 'INT. KITCHEN - NIGHT') and passes with this change.
  • pnpm run lint and pnpm run test (38 tests) pass locally.
  • Two-browser check (local signaling worker): A typed FROMA, then B appended FROMB. Both ended with FROMAFROMB. Mid-text insertion keeps the caret in place, and text survives a reload.

Browser B after both edits (A's presence pointer visible):

Browser B showing FROMAFROMB synced from both browsers

Browser A after both edits:

Browser A showing FROMAFROMB synced from both browsers

Still needed on write.subscript.to (deployment, not code)

The hosted site uses the default signaling URL wss://y-webrtc-eu.fly.dev (the <subscript-write> embed sets no signaling-url). That server no longer responds; connections time out. Until the embed points at a working signaling server (for example a deployed signaling/ worker), browsers on write.subscript.to still can't find each other. A follow-up issue will be filed for this when this PR merges.

Changelog

No changelog entry: the project has no changelog.

Closes #1

Agents: claude-code (claude-opus-5-5)

lsegal added 3 commits October 3, 2026 14:11
Input events fire on the contentEditable host rather than the paragraph
being typed in, so the per-paragraph onInput handler never ran and typing
was only written to the Yjs document on Enter or Tab. Handle input on the
host, resolve the edited paragraph from the selection, and preserve the
caret across the resulting re-render.

Closes #1
@lsegal lsegal changed the title Fix Share Draft links not syncing edits between browsers Fix typed text never reaching shared drafts Oct 3, 2026
@lsegal
lsegal marked this pull request as ready for review October 3, 2026 21:41
@lsegal
lsegal merged commit a778c04 into main Oct 3, 2026
1 check passed
@lsegal
lsegal deleted the fix/issue-1-share-sync branch October 3, 2026 21:41
@lsegal

lsegal commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged. Follow-ups filed:

Manual verification

CI can't cover these: they need real deployed infrastructure and separate devices.

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.

Sharing not working: Share Draft link doesn't sync updates between browsers

1 participant