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

Improve type-safety when using createFileMap #5428

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

eps1lon
Copy link
Collaborator

@eps1lon eps1lon commented Dec 31, 2022

Extracted from #5426

@@ -46,20 +46,20 @@ const SandpackGlimmer = ({code}: {code: string}) => (
);

export default memo(function SandpackWrapper(props: any): any {
const codeSnippet = createFileMap(Children.toArray(props.children));
const codeSnippets = Children.toArray(props.children) as React.ReactElement[];
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using same pattern as beta/src/components/MDX/Sandpack/SandpackRoot.tsx. Should we pass files as a prop instead of recomputing in beta/src/components/MDX/Sandpack/SandpackRoot.tsx?

@github-actions
Copy link

github-actions bot commented Dec 31, 2022

Size Changes

📦 Next.js Bundle Analysis

This analysis was generated by the next.js bundle analysis action 🤖

Three Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/404 43.64 KB (🟡 +3 B) 132.78 KB
/500 43.62 KB (🟡 +3 B) 132.76 KB
/[[...markdownPath]] 43.71 KB (🟡 +3 B) 132.84 KB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 10% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

@eps1lon eps1lon marked this pull request as ready for review December 31, 2022 15:41
@vercel
Copy link

vercel bot commented Dec 31, 2022

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

Name Status Preview Updated
reactjs-org 🔄 Building (Inspect) Dec 31, 2022 at 3:44PM (UTC)

@@ -74,7 +74,7 @@ function SandpackRoot(props: SandpackProps) {

files['/styles.css'] = {
code: [sandboxStyle, files['/styles.css']?.code ?? ''].join('\n\n'),
hidden: !files['/styles.css']?.visible,
hidden: files['/styles.css']?.hidden,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

files used to be any since createFileMap returned any. Now that we type the input of createFileMap, TypeScript is able to infer a more accurate return type of createFileMap.

@@ -74,7 +74,7 @@ function SandpackRoot(props: SandpackProps) {

files['/styles.css'] = {
code: [sandboxStyle, files['/styles.css']?.code ?? ''].join('\n\n'),
hidden: !files['/styles.css']?.visible,
hidden: files['/styles.css']?.hidden,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Couldn't find neither css styles.css hidden nor css styles.css visible so maybe this should be

Suggested change
hidden: files['/styles.css']?.hidden,
hidden: true,

instead which would match the old behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants