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

fix(open in codesandbox button): optimize for long sandoxes #120

Merged
merged 3 commits into from
Dec 8, 2021

Conversation

danilowoz
Copy link
Member

@danilowoz danilowoz commented Nov 3, 2021

This introduces a breaking change due to useCodeSandboxLink is no longer used to generate the URL. From now on, the UnstyledOpenInCodeSandboxButton is responsible for managing the URL or the form that will create a new sandbox in the CodeSandbox.

In the previous approach, all the parameters to create a sandbox in the CodeSandbox were attached directly in the URL, making it easily reach the request too long (401). That's why we deprecated the hook in favor of using a whole new component, which is responsible for either using an anchor (for short sandboxes) or a form-POST (for long sandboxes).

The UnstyledOpenInCodeSandboxButton is a basic component that doesn't carry any style, so if you want a ready-to-use component, use the OpenInCodeSandboxButton instead, which contains the CodeSandbox logo and the same functionality.


Migration guide:

import {
--  useCodeSandboxLink,
++  UnstyledOpenInCodeSandboxButton
}
const CustomOpenInCSB = () => {
--  const url = useCodeSandboxLink();
--  return <a href={url}Open in CodeSandbox</a>
++  return <UnstyledOpenInCodeSandboxButton>pen in CodeSandbox</UnstyledOpenInCodeSandboxButton>
   );
};

CSB-519

@danilowoz danilowoz requested a review from alexnm November 3, 2021 16:12
@danilowoz danilowoz self-assigned this Nov 3, 2021
@vercel
Copy link

vercel bot commented Nov 3, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/codesandbox/sandpack/6xMena4KZ2GL6Z4118YH1B4ARUeF
✅ Preview: https://sandpack-git-fix-optimize-open-sandbox-codesandbox1.vercel.app

@vercel vercel bot temporarily deployed to Preview November 3, 2021 16:12 Inactive
Copy link
Collaborator

@alexnm alexnm left a comment

Choose a reason for hiding this comment

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

Left a few comments, but nothing to block the PR if you have other priorities right now

sandpack-react/src/index.ts Outdated Show resolved Hide resolved
sandpack-react/src/common/BareCodeSandboxButton.tsx Outdated Show resolved Hide resolved
sandpack-react/src/common/BareCodeSandboxButton.tsx Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview – sandpack November 25, 2021 14:44 Inactive
@vercel vercel bot temporarily deployed to Preview – sandpack-landing November 25, 2021 14:44 Inactive
@daryl-cecile
Copy link

It seems the export for useCodeSandboxLink in 'sandpack-react/src/hooks/index.ts' needs to be removed

@andreifloricel
Copy link
Contributor

andreifloricel commented Dec 5, 2021

Hi @danilowoz, I just stumbled on this limitation (401 on long requests) and wanted to open an issue but then noticed this PR :)
Is this fix planned for a coming release?

@vercel vercel bot temporarily deployed to Preview – sandpack-docs December 8, 2021 09:37 Inactive
@vercel vercel bot temporarily deployed to Preview – sandpack-theme December 8, 2021 09:37 Inactive
@vercel vercel bot temporarily deployed to Preview – sandpack-landing December 8, 2021 09:37 Inactive
@vercel vercel bot temporarily deployed to Preview – sandpack-docs December 8, 2021 09:40 Inactive
@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 8, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 08ceba9:

Sandbox Source
Sandpack Blog Example 1 Configuration

@danilowoz danilowoz requested a review from sannek December 8, 2021 09:40
@vercel vercel bot temporarily deployed to Preview – sandpack-theme December 8, 2021 09:41 Inactive
@vercel vercel bot temporarily deployed to Preview – sandpack-landing December 8, 2021 09:41 Inactive
Copy link
Contributor

@sannek sannek left a comment

Choose a reason for hiding this comment

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

Some small docs suggestion ❤️ Looks great tho!

website/docs/docs/advanced-usage/components.md Outdated Show resolved Hide resolved
website/docs/docs/advanced-usage/components.md Outdated Show resolved Hide resolved
Co-authored-by: Sanne <sanne@codesandbox.io>
@vercel vercel bot temporarily deployed to Preview – sandpack-docs December 8, 2021 10:24 Inactive
@vercel vercel bot temporarily deployed to Preview – sandpack-landing December 8, 2021 10:24 Inactive
@vercel vercel bot temporarily deployed to Preview – sandpack-theme December 8, 2021 10:24 Inactive
Co-authored-by: Sanne <sanne@codesandbox.io>
@vercel vercel bot temporarily deployed to Preview – sandpack-docs December 8, 2021 10:27 Inactive
@vercel vercel bot temporarily deployed to Preview – sandpack-landing December 8, 2021 10:30 Inactive
@danilowoz danilowoz merged commit 3ad5261 into main Dec 8, 2021
@danilowoz danilowoz deleted the fix/optimize-open-sandbox branch December 8, 2021 10:35
@vercel vercel bot temporarily deployed to Preview – sandpack-theme December 8, 2021 10:37 Inactive
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.

5 participants