Skip to content

fix(playground): better handle multiple files for Javascript #3119

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 5 commits into from
Sep 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/components/global/Playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,10 @@ export default function Playground({
version,
};

let codeBlock;
if (!hasUsageTargetOptions) {
// codeSnippets are React components, so we need to get their rendered text
// using outerText will preserve line breaks for formatting in Stackblitz editor
codeBlock = codeRef.current.querySelector('code').outerText;
} else {
codeBlock = codeRef.current.querySelector('code').outerText;
// using outerText will preserve line breaks for formatting in Stackblitz editor
let codeBlock = codeRef.current.querySelector('code').outerText;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we ever re-assign codeBlock, if not this can be a const.


if (hasUsageTargetOptions) {
editorOptions.files = Object.keys(codeSnippets[usageTarget])
.map((fileName) => ({
[fileName]: hostRef.current!.querySelector<HTMLElement>(`#${getCodeSnippetId(usageTarget, fileName)} code`)
Expand Down