Era-correctness pass: make snippets run on pinned versions - #184
Conversation
… versions
The repo targets React 16.6-16.8 / RR v5 / Enzyme 3 / webpack 4 / Babel 7 /
CRA 3 (per examples/*/package.json). This pass keeps that era but fixes the
snippets that don't actually work against those pinned versions.
11_webpack.md
- clean-webpack-plugin: lesson used the v2 positional API
(`new CleanWebpackPlugin(pathsToClean, cleanOptions)`) but examples pin
^3.0.0. v3 dropped that signature in favor of a single options object
with `cleanOnceBeforeBuildPatterns` and made the export named.
Rewrote to: `const { CleanWebpackPlugin } = require('clean-webpack-plugin')`
+ `new CleanWebpackPlugin({ cleanOnceBeforeBuildPatterns: ['**/*',
'!template.html', '!manifest.json', '!favicon.ico'], ... })`.
- webpack-dev-middleware: both `require('webpack-dev-middleware')(compiler,
config.devServer)` calls were passing webpack-dev-server's `devServer`
block (contentBase/hot/overlay) where wdm v3 expects its own options
(publicPath/stats/mimeTypes). Silently ignored. Replaced with
`{ publicPath: config.output.publicPath || '/', stats: 'minimal' }`.
- webpack-hot-middleware: was being passed `config.devServer` too; now
invoked with default options (whm reads `path`/`log`/`heartbeat`, not
devServer).
- css-loader: all 4 occurrences used the deprecated `query:` key. css-loader
v3 (pinned in examples) expects `options:`; `query:` triggers a warning.
Also updated the `modules`/`localIdentName` shape to css-loader v3's
nested form (`modules: { localIdentName: ... }`).
- Babel package list: the bulleted list was Babel-6 names
(`babel-core`/`babel-preset-env`/etc.) while the install command below
used Babel-7 namespaces (`@babel/core`/`@babel/preset-env`/etc.).
Aligned the list to match the actual command and added
`@babel/plugin-proposal-class-properties` which the command installs.
- express-static-gzip: the v1.1.x pin doesn't support `orderPreference`
(that option was added in v2). Removed the explicit ordering and let
v1's default behavior serve `.br` when the client accepts it, with a
short explanation of the fallback chain.
10_unit-tests.md
- Removed the `jest-cli@20.0.4` pin and the misleading "react-scripts is
locked at 20.0.4" note. CRA 2 shipped Jest 23, CRA 3 ships Jest 24
(which is what examples/*/package.json pin). The lesson now installs
only `enzyme` + `enzyme-adapter-react-16`.
08_redux.md
- Reworked the redux-promise → redux-thunk transition section. Added the
missing `import reduxThunk from 'redux-thunk';` and the install command
(the lesson was using `reduxThunk` without ever importing it).
- Made the reducer transition explicit: under redux-promise the reducer
read `action.payload.data`; with the new thunk dispatching
`payload: response.data` directly, the reducer drops the `.data` hop
to become `_.mapKeys(action.payload, 'id')`. Replaced the stale
"replace `return [...state, ...action.payload];`" wording (which never
matched the current reducer body).
- Removed the obsolete TODO comment about explaining Object.assign by
actually explaining it inline.
09_packages.md
- Axios action-creator example: clarified that the snippet only works
with `redux-promise` applied to the store — without it,
`action.payload.data` would be undefined because payload is still an
unresolved Promise. Removed the modernization heads-up about Redux
Toolkit (we're keeping the era).
- Added a `javascript` language tag to the previously bare ```` ``` ````
fence opening the router example (markdownlint MD040).
05_controlled-components.md
- react-throttle: added the missing `import { Debounce } from 'react-throttle';`,
changed `time="400"` to `time={400}` to match the documented numeric
prop, and clarified that the input becomes uncontrolled while Debounce
manages when onChange fires.
📝 WalkthroughWalkthroughFive React tutorial lesson files are updated to modernize package versions and API usage. Debounce setup is clarified, jest-cli is removed from testing deps, Redux async handling switches to thunk, and Webpack examples update Babel scopes, clean-plugin v3, middleware options, and CSS loader configuration. ChangesComponent Input & Testing Modernization
Redux Async Middleware Migration
Webpack & Build Configuration Modernization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
10_unit-tests.md (1)
30-30: 💤 Low valueCorrect guidance! Successfully removes the incorrect jest-cli pin.
The note correctly advises against installing
jest-cliand explains that CRA's bundled Jest is sufficient. This aligns with the PR objective to remove incorrect jest-cli@20.0.4 guidance.Optional precision improvement: Since the repository targets CRA 3 specifically (per PR objectives), you could tighten "currently in the 23/24 series, depending on your CRA version" to "currently Jest 24 in CRA 3" for era-specific accuracy. However, the current phrasing acknowledges variation across CRA versions, which may be intentional.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@10_unit-tests.md` at line 30, Update the guidance in the note about CRA's bundled Jest to be more specific for this repo: replace the phrase "currently in the 23/24 series, depending on your CRA version" with "currently Jest 24 in CRA 3" so the note accurately reflects that this repository targets CRA 3 and therefore ships Jest 24; keep the rest of the sentence about not installing jest-cli and not pinning jest-cli@20.0.4 intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@08_redux.md`:
- Around line 849-851: The fenced code block containing the npm install command
("npm install --save redux-thunk") lacks a language identifier; update that
fence to include a shell language (e.g., change the opening fence to ```bash or
```shell) so the block becomes ```bash followed by the command and the closing
``` to satisfy MD040 and enable proper syntax highlighting.
In `@11_webpack.md`:
- Around line 427-429: Replace the deprecated presets listed
(`@babel/preset-es2015`, `@babel/preset-stage-2`) with Babel 7-compatible
packages: use `@babel/preset-env` instead of `@babel/preset-es2015`, and remove
`@babel/preset-stage-2` and add the specific proposal plugins you need (for
example `@babel/plugin-proposal-class-properties` for class fields); also update
any install commands to install `@babel/preset-env` and the chosen
`@babel/plugin-proposal-*` plugins instead of the removed presets.
---
Nitpick comments:
In `@10_unit-tests.md`:
- Line 30: Update the guidance in the note about CRA's bundled Jest to be more
specific for this repo: replace the phrase "currently in the 23/24 series,
depending on your CRA version" with "currently Jest 24 in CRA 3" so the note
accurately reflects that this repository targets CRA 3 and therefore ships Jest
24; keep the rest of the sentence about not installing jest-cli and not pinning
jest-cli@20.0.4 intact.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: deea6dc3-3583-42da-8a3d-81fa672676d1
📒 Files selected for processing (5)
05_controlled-components.md08_redux.md09_packages.md10_unit-tests.md11_webpack.md
| ``` | ||
| npm install --save redux-thunk | ||
| ``` |
There was a problem hiding this comment.
Add language identifier to code fence.
The npm install command block should specify bash or shell as the language identifier for proper syntax highlighting and to satisfy markdown linters.
📝 Proposed fix
-```
+```bash
npm install --save redux-thunk</details>
As per coding guidelines, the static analysis tool flagged: "Fenced code blocks should have a language specified (MD040, fenced-code-language)".
<details>
<summary>🧰 Tools</summary>
<details>
<summary>🪛 markdownlint-cli2 (0.22.1)</summary>
[warning] 849-849: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
</details>
</details>
<details>
<summary>🤖 Prompt for AI Agents</summary>
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @08_redux.md around lines 849 - 851, The fenced code block containing the npm
install command ("npm install --save redux-thunk") lacks a language identifier;
update that fence to include a shell language (e.g., change the opening fence to
bash or shell) so the block becomes bash followed by the command and the closing to satisfy MD040 and enable proper syntax highlighting.
</details>
<!-- fingerprinting:phantom:triton:puma -->
<!-- d98c2f50 -->
<!-- This is an auto-generated comment by CodeRabbit -->
| * @babel/preset-es2015 | ||
| * @babel/preset-react | ||
| * @babel/preset-stage-2 |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Are @babel/preset-es2015and@babel/preset-stage-2 valid packages in Babel 7?
💡 Result:
Yes for “are they valid packages to install and reference”, but no for the intent of Babel 7 compatibility: both presets are deprecated/removed in Babel 7’s recommended preset set. 1) @babel/preset-es2015 - Babel’s docs recommend using @babel/preset-env instead of the old yearly preset approach; Babel notes that if you see a preset like babel-preset-es2015 you should migrate to preset-env. [1] - Babel also has documentation pages for @babel/preset-es2015, indicating the preset package name exists and is documented. [2] - However, the “yearly presets” were deprecated in Babel 6, and the recommended replacement for Babel 7 is @babel/preset-env. [1][3] 2) @babel/preset-stage-2 - Babel’s docs state that as of Babel 7, all the “stage” presets are deprecated. [4] - Babel’s presets documentation similarly says Stage-X (experimental) presets were deprecated and stopped publishing in Babel 7; it recommends specifying proposals as plugins rather than using a catch-all preset. [5] - Babel’s migration guidance also states “We are removing the stage presets in favor of explicit proposal usage.” [3] Practical takeaway - @babel/preset-es2015 is not the recommended choice in Babel 7 (migrate to @babel/preset-env). [1][3] - @babel/preset-stage-2 is deprecated and should not be relied on in Babel 7; migrate by using the specific proposal plugins instead. [4][5][3] If you tell me your current Babel config and intended target environments, I can suggest an equivalent Babel 7 config.
Citations:
- 1: https://babeljs.io/docs/en/env/
- 2: https://babeljs.io/docs/en/babel-preset-es2015
- 3: https://babeljs.io/docs/v7-migration
- 4: https://babeljs.io/docs/babel-preset-stage-2
- 5: https://babeljs.io/docs/presets
Replace deprecated Babel presets for Babel 7 compatibility.
Lines 427–429 list @babel/preset-es2015 and @babel/preset-stage-2, both of which are deprecated and removed in Babel 7. Per Babel's official migration docs:
@babel/preset-es2015should be replaced with@babel/preset-env@babel/preset-stage-2was removed entirely; use explicit proposal plugins instead (e.g.,@babel/plugin-proposal-class-propertiesfor class properties)
Update the snippet and install command to reflect the correct packages for Babel 7.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@11_webpack.md` around lines 427 - 429, Replace the deprecated presets listed
(`@babel/preset-es2015`, `@babel/preset-stage-2`) with Babel 7-compatible
packages: use `@babel/preset-env` instead of `@babel/preset-es2015`, and remove
`@babel/preset-stage-2` and add the specific proposal plugins you need (for
example `@babel/plugin-proposal-class-properties` for class fields); also update
any install commands to install `@babel/preset-env` and the chosen
`@babel/plugin-proposal-*` plugins instead of the removed presets.
Summary
The repo's lessons are intentionally pinned to React 16.6-16.8 / React Router v5 / Enzyme 3 / webpack 4 / Babel 7 / CRA 3 (per
examples/*/package.json). This PR keeps that era — no React 18, no RTL, no React Router v6, no Redux Toolkit, no Vite — but fixes the snippets that don't actually run against those pinned versions.Genuine era bugs (would fail on a fresh install of the pinned versions)
clean-webpack-pluginv3 API. Lesson used the v2 positional API (new CleanWebpackPlugin(pathsToClean, cleanOptions)) but examples pin^3.0.0. v3 dropped positional args and switched to a named import + single options object withcleanOnceBeforeBuildPatterns. As written, the lesson's call silently did nothing.webpack-dev-middlewaremisconfigured. Both call sites passedconfig.devServer(contentBase/hot/overlay— those arewebpack-dev-serveroptions, not wdm's). wdm v3 expectspublicPath/stats/mimeTypesand silently ignored the wrong block. Replaced with the correct options.webpack-hot-middlewarewas also being passedconfig.devServer. Same issue; switched to defaults (whm's real options arepath/log/heartbeat).css-loaderdeprecatedquery:key. All 4 occurrences usedquery:which css-loader v3 (pinned) accepts only with a deprecation warning. Renamed tooptions:and updated themodules/localIdentNameshape to v3's nested form (modules: { localIdentName: '…' }).babel-core,babel-preset-env, etc.) while the install command below it used Babel-7 namespaces (@babel/core,@babel/preset-env, etc.). Aligned the list to the actual command and added@babel/plugin-proposal-class-properties.express-static-gzipoption mismatch. The lesson usedorderPreference: ['br']but the example pins^1.1.3, and that option was only added in v2.0.0. v1.x silently ignored it. Removed the explicit ordering and explained v1's default Brotli-preferred fallback chain.10_unit-tests.mdJest pin. Lesson installedjest-cli@20.0.4and claimed "react-scripts is locked at 20.0.4". Wrong even at the time — CRA 2 shipped Jest 23, CRA 3 (which the examples pin) shipped Jest 24. Removed the pin and the misleading note; lesson now installs justenzyme+enzyme-adapter-react-16.08_redux.mdredux-thunk transition.reduxThunkwithout ever showingimport reduxThunk from 'redux-thunk';.return [...state, ...action.payload];" which never matched the current reducer body. Rewrote so it's clear what the prior body was (_.mapKeys(action.payload.data, 'id')under redux-promise) and why the.datahop disappears (the thunk dispatchespayload: response.datadirectly).09_packages.mdAxios snippet. Made it explicit that the snippet's reducer readingaction.payload.dataonly works becauseredux-promiseis applied to the store; without that middleware,payloadarrives as an unresolved Promise. Also added ajavascriptlanguage tag to the previously bare```fence (markdownlint MD040).05_controlled-components.mdDebounce snippet. Added the missingimport { Debounce } from 'react-throttle';, changedtime="400"to the documented numerictime={400}, and clarified that removingvalue=…makes the input uncontrolled while Debounce manages whenonChangefires.Out of scope (era choice, per the existing pin policy)
createRootand React 19Switch/Route component=left intact)createAsyncThunk/ RTK Query@babel/polyfilldeprecated in 7.4 (works in the 7.0-7.2 era pinned)react@16Test plan
examples/*/package.json.11_webpack.mdagainst itself: clean-webpack-plugin, webpack-dev-middleware, webpack-hot-middleware, css-loader (×4), express-static-gzip, Babel package list.08_redux.mdstill chains correctly end-to-end: action types → action creators → reducer → store wiring → connectedApp.js. Both the redux-promise and redux-thunk phases.09_packages.mdreads with the new "redux-promise required" note.react-throttlesnippet now includes theDebounceimport and numerictimeprop.Summary by CodeRabbit