Skip to content

Conversation

@wellreadundead
Copy link
Contributor

@wellreadundead wellreadundead commented Sep 19, 2025

Problem

The current share feature has a hard limit of 2047 characters after gzip and url-encoding. This is due to browser limitations on how long a query param value can be.

Also it doesn't support sharing code with emojis.

Solution

It turns out that the fragment (#) part of the url is more suited to this purpose than the query param. It actually isn't sent to the server and instead is only parsed on the client. Because of that, browsers don't restrict the size of the fragment portion of the URL to the same extent that they do with query params. Practically, chrome does limit the size of the URL to 2MB so that's what I set as the limit.

Gemini Deep Research actually discovered this for me, although I did write all of the code by hand: https://g.co/gemini/share/9712e01a0afe

Supporting unicode was as simple as processing each character in the array buffer one by one instead of all at once. This is probably slower but sharing doesn't have to be realtime

Example:

I went ahead and copied an entire copy of Frankenstein. Attempting to run the "code" will crash the interpreter but the share function works just fine!

Screen.Recording.2025-09-18.at.8.21.46.PM.mov.mp4

Increase share limit by using the fragment (#) part of the URL instead of a query param. Also fixes an issue sharing unicode characters outside of the latin1 character set
@vrn-sn
Copy link
Member

vrn-sn commented Sep 19, 2025

I was testing this out and noticed that if you go to a link using the old share parameter, and then click share again, we append the new fragment. Can we instead just replace the share parameter with #?

Currently, it results in a URL like this: https://luau.org/demo?share=<ENCODED_STRING>#<ENCODED_STRING>.

Fixed an issue where we would duplicate share link and fragment
@wellreadundead
Copy link
Contributor Author

I was testing this out and noticed that if you go to a link using the old share parameter, and then click share again, we append the new fragment. Can we instead just replace the share parameter with #?

Currently, it results in a URL like this: https://luau.org/demo?share=<ENCODED_STRING>#<ENCODED_STRING>.

Good find, it was a pretty painless fix

Screen.Recording.2025-09-19.at.2.49.50.PM.mov.mp4

Copy link
Member

@vrn-sn vrn-sn left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for the contribution!

@vrn-sn vrn-sn merged commit 2d33fe8 into luau-lang:master Sep 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants