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

[lexical-playground][file] Feature: Playground link sharing #6028

Merged
merged 11 commits into from
May 11, 2024

Conversation

etrepum
Copy link
Collaborator

@etrepum etrepum commented May 4, 2024

Description

Adds a share button to the playground's ActionToolbar which will create a #doc= URL that includes a compressed and serialized document. The plugin also has an effect that will set the editor state from this document and clear history on initial load. It changes the URL when the share button is clicked as well, I just copied the typescript playground UX for this, I think it's done as a fallback for if the clipboard.writeText fails.

I added the following new exports to @lexical/file to support this feature:

  • type SerializedDocument
  • serializedDocumentFromEditorState
  • editorStateFromSerializedDocument

Here's an example link with #doc= in the preview

Test plan

  • Change some content from the editor's default state
  • Click the share button
  • Expect the URL to change with a #doc=... hash, the URL to be on the clipboard, and the "URL copied to clipboard" flash message to show
  • Paste it into another browser (or make some changes and reload) and expect that the previously shared state to be restored (only the state, no history)

There's some unit tests that ensure round-trip of the doc<->hash and an e2e test that runs the above test plan

Copy link

vercel bot commented May 4, 2024

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

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 5, 2024 8:20pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 5, 2024 8:20pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 4, 2024
@etrepum
Copy link
Collaborator Author

etrepum commented May 4, 2024

@zurfyx any thoughts on this before I finish up the UI and tests?

Copy link
Member

@zurfyx zurfyx left a comment

Choose a reason for hiding this comment

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

Brilliant, thank you for putting this together!

@etrepum etrepum changed the title [WIP] [playground][file] Feature: Playground link sharing [WIP] [lexical-playground][file] Feature: Playground link sharing May 5, 2024
@acywatson
Copy link
Contributor

this is pretty cool - I'm not sure how useful it will be for real-life debugging, but I might be wrong and there's certainly no harm. Curious if you had particular use cases/debugging friction points in mind.

Another area of exploration might be the test generator - I think it's defunct and never worked super-well, but the idea was to be able to start "recording mode" and it would generate an e2e test for you as you interacted with the playground editor.

@etrepum
Copy link
Collaborator Author

etrepum commented May 5, 2024

@acywatson I picked it off the roadmap 🤷‍♂️ Thinking about debugging use cases I think it is actually pretty useful because you can make a link to the playground from an issue with the state required to repro an issue (so long as history isn't involved in the bug). You can also use it to demonstrate a playground state that shows off a new node or feature. It's also in just about every other playground site.

@etrepum etrepum changed the title [WIP] [lexical-playground][file] Feature: Playground link sharing [lexical-playground][file] Feature: Playground link sharing May 5, 2024
@acywatson
Copy link
Contributor

@acywatson I picked it off the roadmap 🤷‍♂️ Thinking about debugging use cases I think it is actually pretty useful because you can make a link to the playground from an issue with the state required to repro an issue (so long as history isn't involved in the bug). You can also use it to demonstrate a playground state that shows off a new node or feature. It's also in just about every other playground site.

Makes sense!

so long as history isn't involved in the bug

I suspect most issues actually involve a sequence of interactions against a particular initial state, but at least it gets us that initial state.

Once again, no objections to this at all, more just thinking about what could be a next step to making it even easier to create shareable repros and further reduce triage/maintenance overhead.

@acywatson acywatson merged commit 0049452 into facebook:main May 11, 2024
45 checks passed
@etrepum etrepum deleted the playground-state-sharing branch May 11, 2024 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants