Skip to content

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

Closed

Description

@LookRain
  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

Activity

  1. geeseyj commented on Dec 15, 2023

    @geeseyj
    Contributor

    Taking a look at this.

  2. geeseyj commented on Dec 15, 2023

    @geeseyj
    Contributor

    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.

  3. added a commit that references this issue on Jan 31, 2024
    bb65ace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions