Migrate from Angular 9 to React 18 + TypeScript + Vite#243
Open
devin-ai-integration[bot] wants to merge 3 commits into
Open
Migrate from Angular 9 to React 18 + TypeScript + Vite#243devin-ai-integration[bot] wants to merge 3 commits into
devin-ai-integration[bot] wants to merge 3 commits into
Conversation
- Replace Angular CLI / Webpack with Vite + @vitejs/plugin-react - Replace RxJS Observables with async/await fetch - Replace Angular services with React Context (SettingsContext) - Replace router with react-router-dom v6 (BrowserRouter, lazy routes) - Replace Angular Service Worker with vite-plugin-pwa (Workbox) - Port all components, types, scss to React structure - Preserve SCSS theme system and PWA capabilities Co-Authored-By: Charity Quinn <charity.quinn@cognition.ai>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
- SettingsContext: don't persist system-derived theme to localStorage so the prefers-color-scheme listener continues to fire on subsequent changes (was self-disabling after the first OS dark-mode flip). - App: add id="content" to the main wrapper div so the skip-navigation link in index.html points at a real element again (target was removed along with the old Angular app-loader). Co-Authored-By: Charity Quinn <charity.quinn@cognition.ai>
Without the ok-check, a non-2xx poll sub-response would be parsed as a PollResult with undefined fields, causing poll_votes_count to become NaN and poll bars to render at 0% width. Co-Authored-By: Charity Quinn <charity.quinn@cognition.ai>
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.
Summary
Full migration of this Hacker News PWA from Angular 9 + RxJS + Angular CLI to React 18 + TypeScript + Vite, preserving every feature, the SCSS theme system, and PWA capabilities.
What changed
@vitejs/plugin-react@angular/router→react-router-domv6 (BrowserRouter,Routes,useParams,useNavigate,useLocation)SettingsService(Angular DI) →SettingsContext(React Context) — same localStorage keys, sameprefers-color-schemelistenerObservable<T>→ plainasync/awaitusingunfetch; poll items fetched withPromise.allCommentPipe→formatCommentutil functionloadChildren/ Angular module lazy routes →React.lazy+SuspenseforItemDetailsandUserpages@angular/service-worker+ngsw-config.json→vite-plugin-pwa(Workbox) withregisterType: 'autoUpdate'and aNetworkFirstruntime cache for the HN APIrouter.eventssubscription →useLocation()+useEffectto firega('set', 'page', …)/ga('send', 'pageview')on each navigation_themes.scss,_theme_variables.scss,_media.scss) preserved unchanged; only:host >>>(Angular-specific) selectors rewritten to plain class selectorsFile layout (new)
index.html(root, Vite convention) — same meta tags, theme-color, GA snippet, with<div id="root">vite.config.ts— React + PWA plugins, sass deprecation silencingsrc/main.tsx— React 18createRootApp.tsx—BrowserRouter+SettingsProvider+ theme class wrapper +Suspensetypes/—story.ts,comment.ts,user.ts,settings.ts,poll-result.ts,feed-type.ts,unfetch.d.tsservices/hackernews-api.tscontexts/SettingsContext.tsxutils/formatComment.tscomponents/—Header.tsx,Footer.tsx,Settings.tsx,Loader.tsx,ErrorMessage.tsx,Item.tsx,Comment.tsx(+ component scss alongside)pages/—Feed.tsx,ItemDetails.tsx(lazy),User.tsx(lazy)scss/—_themes.scss,_theme_variables.scss,_media.scss(unchanged)public/assets/,public/favicon.ico,public/manifest.json(preserved)vercel.json— SPA rewrite toindex.htmlfor client-side routingRemoved
angular.json,tsconfig.app.json,tsconfig.spec.json,tslint.json,karma.conf.js,protractor.conf.js,ngsw-config.json, the entiresrc/app/,src/main.ts,src/polyfills.ts,src/test.ts, plus all@angular/*,rxjs,zone.js,codelyzer,karma*,protractor,tslint, etc. frompackage.json.Local verification
npm run buildsucceeds (tsc --noEmit+ Vite build, PWA SW generated).npm run devrenders the news feed at/news/1, item detail pages (with recursive comment trees), user profile pages, and the settings overlay. External story links open correctly; internalAsk HN-style items deep-link via/item/:id.Review & Testing Checklist for Human
This is a large, risky change — full framework swap — so please run through:
npm install, thennpm run devand visit/news/1,/newest/1,/show/1,/ask/1,/jobs/1— verify pagination (Prev/More) and that the job header text only appears on/jobs/*.Ask HN: Who is hiring?polls) and confirm the per-optionpollBarwidth matchespoints / poll_votes_count * 100%./user/:idpage from a comment, then press the back button — verifyuseNavigate(-1)returns to the item.localStorage(same keys as Angular version:openLinkInNewTab,theme,titleFontSize,listSpacing).nighttheme, then toggle OS dark mode while the app is open and verify the theme follows.npm run build && npm run preview, open DevTools Network tab, navigate to/item/:idand/user/:idfor the first time — verify separate lazy chunks load (ItemDetails-*.jsandUser-*.js).npm run build && npm run preview, install the PWA, then go offline and reload a page that was visited online — verify the app shell renders and previously-fetched API responses are served from the Workboxhn-api-cache.Notes
unfetchwas kept (rather than switching to nativefetch) to mirror the Angular service's dependency choice. Pinned to^4.2.0because5.0.0has a brokenexportsfield in itspackage.jsonthat Vite/Rollup cannot resolve./division operator and thedarken()color function which are deprecated in modern Sass. Rather than touching the theme files (the brief says "Keep the existing SCSS theme system as-is"), the corresponding deprecations are silenced invite.config.tsviacss.preprocessorOptions.scss.silenceDeprecations.:host >>>(deep selectors) — these don't translate cleanly to React. Replaced them with descendant class selectors incomment.component.scss(.comment-text a) anduser.component.scss(.other-details pre) which give equivalent scoping in practice.UA-66348622-3) is preserved from the originalindex.html. Update if a new property is desired.vercel.jsonadds a single rewrite so that direct loads of e.g./item/123are served byindex.htmlinstead of returning 404.Link to Devin session: https://app.devin.ai/sessions/4cde8dc6643742a1a1e90fa77ad38230
Requested by: @charityquinn-cognition