Skip to content

[Docs] Page template CodeSandbox examples are not working #8969

Closed
1 of 1 issue completed
Closed

Description

@cleydyr

At https://eui.elastic.co/docs/components/templates/page-template/, the Page Template example refers to a contentSvg variable that doesn't exist. This breaks the CodeSandBox. In other examples, it's the sideNavSvg variable that is not defined.

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    documentation
    ⚠️ needs validation
    on Aug 17, 2025
  2. added theissue type on Aug 17, 2025
  3. removed
    ⚠️ needs validation
    on Sep 2, 2025
  4. weronikaolejniczak commented on Sep 2, 2025

    @weronikaolejniczak
    Contributor

    Thanks for raising this, @cleydyr!

    You are totally right, we have actually noticed this before but I don't think we have an issue open. Well, now we do...

    The problem is that we're importing some files locally (mainly .svgs) into examples but we don't add those to Codesandbox.

    export const createOpenInCodeSandboxAction =
    ({ files = {}, dependencies }: Options): ActionComponent =>
    ({ activeSource }) => {
    const parameters: string = useMemo(() => {
    const source = activeSource?.code || '';
    // Compute list of extra files that may be passed
    const extraFiles = Object.entries(files).reduce(
    (acc, [file, content]) => {
    acc[file] = { content };
    return acc;
    },
    {} as Record<string, { content: string }>
    );
    return getParameters({
    files: {
    ...defaultCodeSandboxParameters.files,
    'demo.tsx': {
    content: processTsxSource(source),
    },
    'package.json': {
    content: {
    dependencies: {
    ...findExternalDependencies(source),
    ...dependencies,
    },
    },
    },
    ...extraFiles,
    },
    } as any);
    }, [activeSource]);
    return (
    <form
    action="https://codesandbox.io/api/v1/sandboxes/define"
    method="POST"
    target="_blank"
    >
    <input type="hidden" name="parameters" value={parameters} />
    <input
    type="hidden"
    name="query"
    value={`module=/demo.tsx&view=split`}
    />
    <EuiToolTip content="Open in CodeSandbox">
    <EuiButtonIcon
    type="submit"
    size="s"
    iconType={CodeSandboxIcon}
    color="text"
    aria-label="Open in CodeSandbox"
    />
    </EuiToolTip>
    </form>
    );
    };

    It might be feasible to add those files with ☝🏻 but we'd need to extract them from the imports. I don't think it's super straightforward but not that hard either.

    @tkajtoch have you looked into this before? Does the approach I'm outlining make sense to you?

  5. changed the title [-][docs] Page template CodeSandbox examples are not working[/-] [+][Docs] Page template CodeSandbox examples are not working[/+] on Sep 2, 2025
  6. JasonStoltz commented on Sep 16, 2025

    @JasonStoltz
    Contributor
  7. JasonStoltz commented on Sep 16, 2025

    @JasonStoltz
    Contributor

    Forms as well

  8. JasonStoltz commented on Sep 17, 2025

    @JasonStoltz
    Contributor

    Recap from our Triage session (repeats some of what Weronika already said above)

    The Problem
    Code Sandbox links in the EUI documentation are broken, an issue Weronika confirmed is widespread, affecting the entire "forms" category. The root cause is that these examples use local, relative-path imports for assets that are only used in the documentation, such as SVGs or a displayToggles helper component. Code Sandbox cannot resolve these imports because the local files do not exist in its virtual environment.

    Example: displayToggles-

    Example: svg -

    import contentSvg from '!url-loader!./content_paragraph.svg';
    import sideNavSvg from '!url-loader!./content_side_nav.svg';
    import centerSvg from '!url-loader!./content_center.svg';

    Proposed Solution & Technical Details

    Tomasz noted that he he had already fixed most of these cases when converting examples previously but had skipped some that were too time-consuming. He also recalled that another team member had already fixed the
    displayToggles issue for some examples, so the team should look for that solution for reference.

    The solution in general is to use our existing setup that allows us to include additional local files in the payload sent to Code Sandbox, which is necessary for any example using relative path imports. (Which I believe is what Weronika pointed out above).

    However, Weronika noted, this solution may not work for displayToggles, which would be a very large file to send. Additionally, you can not selectively choose which example to send which files to ... all files we add currently get sent to all examples.

    One option to consider would be to simply remove displayToggles from our examples. This is actually not a bad idea, since it typically makes the example code harder to understand for users.

    Triage & Next Steps
    The team agreed that fixing the broken examples is a worthwhile effort, as Code Sandbox is a critical part of the developer workflow. They estimated the effort to fix the known broken examples would be a couple of days, but could be more.

    Because the work is documentation-related and doesn't need to be tied to a specific EUI release, they decided it would be a
    great task to handle during a support week. Jason took the action item to recap the conversation in the GitHub issue and move it to the top of the backlog to be prioritized.

  9. weronikaolejniczak commented on Sep 18, 2025

    @weronikaolejniczak
    Contributor

    @JasonStoltz

    The solution in general is to use our existing setup that allows us to include additional local files (...)

    However, Weronika noted, this solution may not work for displayToggles, which would be a very large file to send.

    Sorry, just to clarify: I didn't say this method won't work for DisplayToggles. I said this about another method that I used when fixing some examples that didn't work in Codesandbox while we were getting EUI+ across the finish line. Simply by moving the code from the local file to the example code. That won't work for DisplayToggles because it's a big component. So we'd need to add it as a separate file to Codesandbox using the extraFiles.

    He also recalled that another team member had already fixed the
    displayToggles issue for some examples, so the team should look for that solution for reference.

    Also, I asked @mgadewoll, @acstll and they don't remember fixing DisplayToggles for Codesandbox. I also verified that none of the examples that use DisplayToggles (all are in the Forms category) work.


    Another idea, building on your proposal is to "move" DisplayToggles to the Demo component and make it configurable for every example. This way, the example code remains pure but we can customize the component using the toggles.

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

Metadata

Metadata

Labels

documentation

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions