Skip to content

Sandpack examples with index.html files throw runtime errors #6487

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

Closed
LookRain opened this issue Dec 14, 2023 · 2 comments
Closed

Sandpack examples with index.html files throw runtime errors #6487

LookRain opened this issue Dec 14, 2023 · 2 comments

Comments

@LookRain
Copy link

  1. https://react.dev/learn/add-react-to-an-existing-project#step-2-render-react-components-anywhere-on-the-page
image 2. https://react.dev/reference/react-dom/createPortal#rendering-react-components-into-non-react-server-markup image

The issue seems to be because the index.html files defined in these examples are not used, instead, the public/index.html defined in the template are used

drumst0ck referenced this issue Dec 15, 2023
* fix(sandpack-template): use custom react sandpack template

* refactor: Remove console.log statement

Remove console.log(filePath); from createFileMap.ts

* style: Update file paths in Sandpack components

Update file paths in Sandpack components to use root folder and variables
@geeseyj
Copy link
Contributor

geeseyj commented Dec 15, 2023

Taking a look at this.

@geeseyj
Copy link
Contributor

geeseyj commented Dec 15, 2023

I opened a PR to revert the breaking change.

The cause is the assumption here that all files within a sandpack example should be nested into a src directory.

/**
* Ideally, we should update all markdown files and all the sandboxes
* to use the same folder structure to include `src`. However, we can
* do the same by prepending the root folder on this function.
*/
const rootFolder = '/src/';

filePath = rootFolder + name;

This breaks examples that use index.html for instance because the merging of objects here results in the template file being used because the given public/index.html has been given the path /src/public/index.html

files={{...template, ...files}}

That gives us a couple options for a solution.

  1. Make createFileMap know (arguably) too much by giving it a "whitelist" of file paths to not nest in a /src/ directory.
  2. Change all the Markdown files 😪 💤 .

At this point unfortunately I think option 2 is the un-sexy, more-correct option.

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

No branches or pull requests

2 participants