Repository navigation
Show every file of multi-file React examples - #2795
Open
vaibhav375 wants to merge 1 commit into
Open
vaibhav375 wants to merge 1 commit into
vaibhav375 wants to merge 1 commit into
Conversation
react.dev only server-renders the active file of a Sandpack example; the other files are only in the page's __NEXT_DATA__ script, which clean_html removes. Read them from there before clean_html runs and show each file under its name, falling back to the rendered file whenever the example can't be paired with its data unambiguously. Fixes freeCodeCamp#2615
vaibhav375
marked this pull request as ready for review
November 21, 2026 14:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2615
react.dev's interactive examples (Sandpack) only server-render the file whose tab is active. The other files are just tab buttons in the HTML, and their source is only in the page's
__NEXT_DATA__script. The coreclean_htmlfilter drops that script andclean_html_react_devdrops the tab buttons, so every multi-file example ends up as a single unnamed code block.Changes
react/sandpack_files_react_devfilter, inserted beforeclean_htmlfor the react.dev versions (19 and 18). It reads the Sandpack examples from__NEXT_DATA__and replaces each rendered example with one_pre-heading+<pre>per tab, in tab order. File paths follow react.dev'screateFileMap.package.jsonis compared as JSON, because Sandpack adds an emptydevDependencieswhen it renders it.clean_html_react_devkeeps the_pre-headingclass and no longer overwritesdata-language, so CSS/HTML/JSON files get the right highlighting. JS files still usejsx.Testing
test/lib/docs/scrapers/react_test.rbruns the React pipeline (19 and 18) on react.dev-shaped markup. It covers all files shown, examples with the same active file, examples that aren't rendered, hidden recipes, an example that fails to match,package.json,{...}options in the file meta, per-file language, and the fallback when the data is missing or doesn't match. Each pairing rule has a test that fails without it.bundle exec rake: 846 runs, 0 failures.thor docs:generate reactonmainvs this branch: same 182 pages and index entries; code blocks go from 2022 to 2388 with 858 file headings. Every code block frommainis still there, except that the six renderedpackage.jsonfiles now show the source without the emptydevDependencies. On<StrictMode>→ "Fixing bugs found by re-running Effects in development",mainshows onlyindex.js; this branch showsindex.js,App.jsandStoryTray.js(checked inrackup).thor docs:generate react@18: 139 pages, 751 file headings, no errors.Examples that stay as they are today: those using
SandpackWithHTMLOutput(they add aShowRenderedHTML.jstab that isn't in the page data), a couple where the server-rendered code is cut short, and one that is ambiguous. That's 12 of the 339 examples on the 124 pages I checked. Onlearn/typescriptthe "TypeScript Playground" link inside the examples also goes away, like the CodeSandbox link already does.