Skip to content

feat: improve examples and move routing logic #31

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

Merged
merged 12 commits into from
Jul 1, 2025

Conversation

brettkolodny
Copy link
Collaborator

Improves the code for handling examples, and moves the routing logic/code share loading from the frontend to the backend.

I also cleaned up the copy a little while I was there

Copy link

vercel bot commented Jun 27, 2025

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

Name Status Preview Comments Updated (UTC)
playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 1, 2025 7:21pm

@brettkolodny brettkolodny marked this pull request as draft June 30, 2025 18:26
@brettkolodny brettkolodny marked this pull request as ready for review June 30, 2025 20:38

return parsedData.output;
} catch (e) {
console.error(`Failed to load playground with id ${id}: ${e}`);
Copy link

Choose a reason for hiding this comment

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

What about displaying a user facing error if there is an issue with getting the share data?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah good call. There isn't really any actionable items the user could take, but looking at what other playgrounds do it seems like it's common to show a 404 page which I think would work well enough

}

return examples.find((e) => e.slug === example)?.code;
return examples[example] ?? null;
Copy link

Choose a reason for hiding this comment

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

Maybe not necessary for this PR but you could add some validation to check if the example slug is valid

const bytes = new TextEncoder().encode(JSON.stringify(data));

// Check if the data is larger than 1mb
if (bytes.length > 1024 * 1000) {
Copy link

@jaaydenh jaaydenh Jul 1, 2025

Choose a reason for hiding this comment

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

you could self document this with a const, const MAX_DATA_SIZE = 1024 * 1000;


const href = `${window.location.origin}/parameters?${params.toString()}`;
{Object.entries(examples).map(([ slug, title ]) => {
const href = `${window.location.origin}/parameters/example/${slug}`;
return (
<DropdownMenuItem key={slug} asChild={true}>
<a href={href} target="_blank" rel="noreferrer">
Copy link

Choose a reason for hiding this comment

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

It could be useful to show external link icons when opening external links

@@ -54,9 +64,7 @@ app.get("*", (c) => {
? "/assets/wasm_exec.js"
Copy link

Choose a reason for hiding this comment

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

You could simplify these paths a bit with something like this,

const getAssetPath = (filename: string) => 
    import.meta.env.PROD ? `/assets/${filename}` : `/${filename}`;

Copy link

@jaaydenh jaaydenh left a comment

Choose a reason for hiding this comment

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

Let a few of small comments but nothing blocking merging this.

@brettkolodny brettkolodny merged commit 8a74059 into main Jul 1, 2025
2 checks passed
@brettkolodny brettkolodny deleted the brett/improve-examples branch July 1, 2025 19:26
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