[Website] Fix all broken CodeSandbox examples#9516
[Website] Fix all broken CodeSandbox examples#9516weronikaolejniczak wants to merge 21 commits intoelastic:mainfrom
Conversation
427e0e1 to
8650d01
Compare
8650d01 to
90d52bb
Compare
There was a problem hiding this comment.
Pull request overview
This pull request updates the EUI docs site demos to better support live editing + CodeSandbox exports by attaching required “extra files” (raw source/assets) to demos, and refreshes a few demo dependencies (notably @faker-js/faker).
Changes:
- Bump
@faker-js/faker(website) and update affected docs snippets. - Add
extraFiles(raw-loaded sources/assets) to many MDX demos so CodeSandbox can include referenced local files. - Improve CodeSandbox demo generation by auto-injecting
@elastic/chartstheme CSS when charts are used.
Reviewed changes
Copilot reviewed 49 out of 50 changed files in this pull request and generated 19 comments.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Updates lockfile for @faker-js/faker version bump. |
| packages/website/src/theme/Demo/actions.tsx | Adds moment-timezone to CodeSandbox dependency set. |
| packages/website/package.json | Bumps @faker-js/faker to ^10.3.0. |
| packages/website/docs/utilities/window-events/index.mdx | Adds raw source as extraFiles for CodeSandbox. |
| packages/website/docs/utilities/text-truncation.mdx | Adds missing imports in snippet. |
| packages/website/docs/utilities/focus-trap/index.mdx | Adds raw source as extraFiles for CodeSandbox. |
| packages/website/docs/utilities/color-palettes/index.mdx | Adds raw source as extraFiles; updates snippet imports. |
| packages/website/docs/utilities/accessibility/index.mdx | Makes snippets self-contained (imports/exports). |
| packages/website/docs/dataviz/types/part-to-whole-comparisons.mdx | Adds raw source extraFiles and adjusts imports in snippets. |
| packages/website/docs/dataviz/types/metric-chart.mdx | Adds raw source extraFiles and adjusts imports in snippets. |
| packages/website/docs/dataviz/theming.mdx | Adds raw source extraFiles and adjusts imports in snippets. |
| packages/website/docs/dataviz/sizing.mdx | Adds raw source extraFiles and adjusts imports in snippets. |
| packages/website/docs/dataviz/accessibility-features.mdx | Adds raw source extraFiles and adjusts imports in snippets. |
| packages/website/docs/components/templates/sitewide-search/index.mdx | Makes snippet self-contained with imports. |
| packages/website/docs/components/templates/page-template/guidelines.mdx | Adds SVG raw sources as extraFiles and imports inside snippet. |
| packages/website/docs/components/tables/basic.mdx | Updates faker API usage and other snippet tweaks. |
| packages/website/docs/components/navigation/facet.mdx | Switches to useEuiPaletteColorBlind hook usage in snippet. |
| packages/website/docs/components/navigation/buttons/group.mdx | Fixes snippet imports to match usage. |
| packages/website/docs/components/navigation/buttons/button.mdx | Fixes import formatting in snippet. |
| packages/website/docs/components/layout/page_components/index.mdx | Adds SVG raw sources as extraFiles and imports inside snippets. |
| packages/website/docs/components/layout/flex/item.mdx | Fixes snippet imports to match usage. |
| packages/website/docs/components/layout/flex/grid.mdx | Corrects demo snippet to use EuiFlexGrid. |
| packages/website/docs/components/forms/text/password.mdx | Wraps demos with extraFiles for shared display_toggles file. |
| packages/website/docs/components/forms/text/basic.mdx | Wraps demos with extraFiles for shared display_toggles file. |
| packages/website/docs/components/forms/selection/switch.mdx | Wraps demo with extraFiles for shared display_toggles file. |
| packages/website/docs/components/forms/selection/super-select.mdx | Wraps demo with extraFiles for shared display_toggles file. |
| packages/website/docs/components/forms/selection/radio-and-radio-group.mdx | Wraps demo with extraFiles for shared display_toggles file. |
| packages/website/docs/components/forms/selection/combo-box.mdx | Wraps multiple demos with extraFiles for shared display_toggles file. |
| packages/website/docs/components/forms/selection/checkbox-and-checkbox-group.mdx | Wraps demo with extraFiles for shared display_toggles file. |
| packages/website/docs/components/forms/selection/basic-select.mdx | Wraps demo with extraFiles for shared display_toggles file. |
| packages/website/docs/components/forms/search-and-filter/search.mdx | Wraps demo with extraFiles for shared display_toggles file. |
| packages/website/docs/components/forms/other/palette-picker.mdx | Wraps demo with extraFiles for shared display_toggles file. |
| packages/website/docs/components/forms/other/file-picker.mdx | Wraps demo with extraFiles for shared display_toggles file. |
| packages/website/docs/components/forms/other/color-picker.mdx | Wraps demos with extraFiles for shared display_toggles file; snippet import tweaks. |
| packages/website/docs/components/forms/numeric/range-sliders.mdx | Wraps demos with extraFiles for shared display_toggles file. |
| packages/website/docs/components/forms/numeric/basic.mdx | Wraps demo with extraFiles for shared display_toggles file. |
| packages/website/docs/components/forms/layouts/form_control_buttons.mdx | Refactors interactive snippet; adds popover + filtering example. |
| packages/website/docs/components/forms/date-and-time/super-date-picker.mdx | Adjusts imports/snippet structure. |
| packages/website/docs/components/forms/date-and-time/date-picker.mdx | Wraps demos with extraFiles for shared display_toggles file. |
| packages/website/docs/components/forms/date-and-time/date-picker-range.mdx | Wraps demos with extraFiles for shared display_toggles file. |
| packages/website/docs/components/editors-and-syntax/markdown/plugins.mdx | Normalizes snippet string quoting/formatting. |
| packages/website/docs/components/editors-and-syntax/markdown/editor.mdx | Removes Docusaurus Link usage in demo snippet; uses EuiLink. |
| packages/website/docs/components/display/icons/index.mdx | Adds raw source extraFiles and makes multiple snippets self-contained. |
| packages/website/docs/components/display/empty-prompt/types_of_empty_states/use_case_images.ts | Adds url-loader mapping for use-case images. |
| packages/website/docs/components/display/empty-prompt/types_of_empty_states/sidebar_snippet.tsx | Reworks demo to use url-loader assets + code string output. |
| packages/website/docs/components/display/empty-prompt/types_of_empty_states/multiple_snippet.tsx | Reworks demo to use url-loader assets + code string output. |
| packages/website/docs/components/display/empty-prompt/types_of_empty_states/empty_snippet.tsx | Reworks demo to use image URL mapping + code string output. |
| packages/website/docs/components/display/empty-prompt/index.mdx | Switches illustration demo to use url/raw loaders and extraFiles. |
| packages/website/docs/components/display/empty-prompt/_multiple_types.tsx | Converts examples to explicit code strings + adds extraFiles/scope for images. |
| packages/docusaurus-theme/src/components/demo/codesandbox/open_action.tsx | Injects @elastic/charts theme CSS imports into CodeSandbox demos. |
Comments suppressed due to low confidence (3)
packages/website/docs/components/forms/other/palette-picker.mdx:21
- This demo's code imports
DisplayTogglesfrom a relative path, but the demo transformer strips allimportstatements for react-live. Without also passingDisplayTogglesvia the<Demo scope={...}>, the interactive preview will throw (undefined component). Consider importingDisplayTogglesin the MDX file and addingscope={{ DisplayToggles }}to the<Demo>props (keepextraFilesfor CodeSandbox).
<Demo extraFiles={{ 'display_toggles.tsx': displayTogglesSource }}>
```tsx interactive
import React, { useState } from 'react';
import {
euiPaletteColorBlind,
euiPaletteForStatus,
packages/website/docs/components/forms/other/file-picker.mdx:17
- This demo's code imports
DisplayTogglesfrom a relative path, but the demo transformer strips allimportstatements for react-live. Without also passingDisplayTogglesvia the<Demo scope={...}>, the interactive preview will throw (undefined component). Consider importingDisplayTogglesin the MDX file and addingscope={{ DisplayToggles }}to the<Demo>props (keepextraFilesfor CodeSandbox).
<Demo extraFiles={{ 'display_toggles.tsx': displayTogglesSource }}>
```tsx interactive
import React, { useState } from 'react';
import {
EuiFilePicker,
EuiFlexGroup,
packages/website/docs/components/forms/numeric/range-sliders.mdx:564
- This demo's code imports
DisplayTogglesfrom a relative path, but the demo transformer strips allimportstatements for react-live. Without also passingDisplayTogglesvia the<Demo scope={...}>, the interactive preview will throw (undefined component). Consider importingDisplayTogglesin the MDX file and addingscope={{ DisplayToggles }}to the<Demo>props (keepextraFilesfor CodeSandbox).
<Demo extraFiles={{ 'display_toggles.tsx': displayTogglesSource }}>
```tsx interactive
import React, { useState } from 'react';
import {
EuiRange,
EuiRangeProps,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/website/docs/components/display/empty-prompt/index.mdx
Outdated
Show resolved
Hide resolved
packages/website/docs/components/forms/layouts/form_control_buttons.mdx
Outdated
Show resolved
Hide resolved
packages/website/docs/components/forms/layouts/form_control_buttons.mdx
Outdated
Show resolved
Hide resolved
packages/website/docs/components/display/empty-prompt/types_of_empty_states/empty_snippet.tsx
Show resolved
Hide resolved
packages/website/docs/components/display/empty-prompt/types_of_empty_states/sidebar_snippet.tsx
Show resolved
Hide resolved
packages/website/docs/components/forms/date-and-time/date-picker-range.mdx
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
packages/website/docs/components/editors-and-syntax/markdown/plugins.mdx
Show resolved
Hide resolved
tkajtoch
left a comment
There was a problem hiding this comment.
I tested all updated CodeSandbox examples. Most of them work beautifully and I'm so glad you were able to find time and fix them! I found a few that are broken:
- EuiEmptyPrompt page is now crashing the browser. I also tried in Incognito and Firefox with the same results.
- Gutter sizing doesn't show the background color in CodeSandbox

- EuiFieldSearch's incremental search example is broken in CodeSandbox
- EuiFilePicker's Removing files programmatically example throws an error in both CodeSandbox and the main docs site
- I know this isn't part of this PR, but could you please address it while you're at it?
Overall, this is a great improvement, and I can't wait till this is shipped and live!
| import { iconSizes, iconSizesText } from './icon_sizes'; | ||
|
|
||
| export default () => ( | ||
| <div css={css`height: fit-content;`}> |
There was a problem hiding this comment.
The reason I'm adding this wrapping div to all Icon examples is because otherwise the EuiCodeBlock is stretched out in Codesandbox and you have to scroll down to see the icons.
There was a problem hiding this comment.
The formatting in this example was all screwed up. The only change needed was adding ChangeEvent import.
|
@tkajtoch Thank you for testing thoroughly 🙏🏻 I'm glad you were able to catch these! 🦅 👁️ ❓ |
| </EuiButton> | ||
| {extraActions.map((ActionComponent) => ( | ||
| <ActionComponent | ||
| key={ActionComponent.displayName ?? ActionComponent.name} |
There was a problem hiding this comment.
This is to get rid of that annoying "key" warning in DevTools console. Not that the lack of key in this case is causing any issues.
| .replace( | ||
| "import Demo from './demo';", | ||
| "import Demo from './demo';\nimport PreviewWrapper from './preview_wrapper';" | ||
| ) | ||
| .replace( | ||
| '<Demo />', | ||
| '<PreviewWrapper>\n <Demo />\n </PreviewWrapper>' | ||
| ), |
There was a problem hiding this comment.
Personally, I don't like this but the only other ideas that came to mind were: 2 separate indexTsxSource variables or a function that modifies the template. That being said, this way was the simplest one.
| return <div css={styles}>{children}</div>; | ||
| }; | ||
|
|
||
| export default FlexPreviewWrapper; |
There was a problem hiding this comment.
Not sure if this needs documenting... That preview wrappers have to be separate .tsx files with a default export.
💚 Build SucceededHistory
|
💚 Build Succeeded
History
|
Tip
I recommend reviewing this PR by commits.
Summary
Resolves #9320
Many CodeSandbox examples were broken. This PR fixes all of them.
@faker-js/fakerto^10.3.0to align the docs preview with CodeSandbox, which resolves latest, and updatedfaker.internet.userName()calls tofaker.internet.username()(renamed in v9).useBaseUrl,useChartBaseTheme) not being available in CodeSandbox - replaced with self-contained alternatives.url-loader, passing them throughscope(react-live) andextraFiles(CodeSandbox).Impact Assessment
Impact level: 🟢 None
QA instructions for reviewer
Test all broken examples. If you feel up for it, you could test all examples.
Update
@faker-js/fakerto latestReplace
LinkwithEuiLinkAdd charts CSS imports
Simple cases (missing import, syntax error)
Complex cases
Checklist before marking Ready for Review
Tests: Added/updated Jest, Cypress, and VRTChangelog: Added changelog entryBreaking changes: Addedbreaking changelabel (if applicable)