-
Notifications
You must be signed in to change notification settings - Fork 24
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
feat: allow sway playground to be opened from docs hub #76
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did need to run git submodule update --init --recursive
-- thanks for that. Should that be added to the docs-hub readme?
I'm happy to help with this, let's sync up about your timeline for this feature.
if (message.origin !== APPROVED_EXTERNAL_DOMAIN) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more secure to handle this on the server side in cors.rs
. But I think an even better way would be to do what rust playground does:
- upload the code to a gist
- use the gist ID as a query parameter
- send the toolchain name as a query parameter as well
- sway playground fetches the code from the gist
Essentially, we can use github gists as a simple database.
Example:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3c65be25f3334da7947b0e120dce23a1
For us it can be a little simpler:
https://sway-playground.org/?toolchain=latest&gist=3c65be25f3334da7947b0e120dce23a1
Sway playground will need to sanitize the string. But then we don't have to worry about cors, and there's no concerns about timing issues.
I would recommend using React router dom's useSearchParams for reading and writing the query params.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this definitely seems like a better approach thanks for the feedback!
} | ||
} | ||
|
||
window.addEventListener('message', setLocalStorageFromExternalDomain); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this out, but it doesn't seem to be working. When the playground link opens, it doesn't have the code from the example, and I don't see any messages in the network tab. I'm guessing it could be a timing issue; perhaps the message is sent before the playground page is rendered (and this useEffect would run).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah it's probably a timing issue. The delay I added on the docshub was through trial and error. Another thing is you need to run the docs hub with NODE_ENV=development pnpm dev
Done in #78 |
We have begun the process of integrating sway playground into the docs hub. To start we simply added a button below full code examples to open the examples in sway playground. For this to be possible this modification to sway-playground is required. Let me know if there is a better way to implement this functionality.
To test this locally, run sway-playground locally, checkout the corresponding docs hub and run that locally as well. You may need to run git submodule update --init --recursive.
corresponding docs hub pr FuelLabs/docs-hub#243