React Production Issues
by John Vincent
Posted on May 12, 2018
This is part of a series of discussions regarding Deploying to a Digital Ocean Droplet.
For more details, please see Deploy TaskMuncher
TaskMuncher React Production Issues
Webpack Production Build
Ensure production code has been optimized.
Add React Developer Tools to Chrome
This adds React Icon.
If the code is not Production ready, the Icon will be red.
If code is Production ready, the icon is blue.
Fix
package.json
"scripts": {
"build": "webpack -p",
"prod": "NODE_ENV=production npm run build",
}
To create the production version
npm run prod
Cannot have two HTML5 back ends at the same time
Problem only shows up in Production on Production servers. Cannot reproduce on a Mac.
Problem is caused by using in 2 places.
Add calendar boolean to CalendarEvent.js
<TaskDialog
calendar
goalId={event.goalId}
projectId={event.projectId}
task={event.task}
close={this.closeEditTaskDialog}
/>
Using package react-tag-input, component TaskDialog
references
import { WithContext as ReactTags } from 'react-tag-input';
which would work fine if it were the only access to package react-dnd
To solve the problem
import { WithOutContext as ReactTagsWithOutContext, WithContext as ReactTagsWithContext } from 'react-tag-input';
and toggle based on boolean calendar
{this.props.calendar ? (
<ReactTagsWithOutContext
id="tags"
inline={false}
tags={this.state.workingTags}
suggestions={suggestions}
minQueryLength={2}
autocomplete
handleDelete={this.handleTagDelete}
handleAddition={this.handleTagAddition}
handleDrag={this.handleTagDrag}
/>
) : (
<ReactTagsWithContext
id="tags"
inline={false}
tags={this.state.workingTags}
suggestions={suggestions}
minQueryLength={2}
autocomplete
handleDelete={this.handleTagDelete}
handleAddition={this.handleTagAddition}
handleDrag={this.handleTagDrag}
/>
)}
Problem is addressed in
node_modules/react-tag-input/example/main.js
Run React Production in Development
Being able to reproduce a production problem in development is a requirement. The production bundle needs to be accessed by the Node/Express app.
Server
middleware.express.js
app.use(express.static(path.resolve(__dirname, '../dist'))); // for testing react prod in dev
Client
Create the production build
npm run prod
which produces the production build in ~/dist
Copy the folder to the server and restart the server.
localhost:3001
to test the app.
React
- Basic React
- Basic React Patterns
- Basic React Redux
- Basic React Redux App
- Basic React Testing with Jest and Enzyme
- Building and deploying MyTunes to johnvincent.io
- Building and deploying React Github Helper App to johnvincent.io
- Deploy React App to Heroku using Travis Continuous Integration
- Deploy TaskMuncher React App to AWS
- First time deploy TaskMuncher React App to Digital Ocean
- Gatsby and Client Only Components
- Gatsby Getting Started
- Gatsby React Icons
- Mac Visual Studio Code
- Material-UI
- Material-UI Pickers
- Material-UI Styling
- Optimizing TaskMuncher with Webpack 4
- Overview of React Gomoku
- Overview of React Hangman
- Overview of React Lights Out
- Overview of React Yahtzee
- React Material-UI
- React Production Issues
- React PropTypes
- React/Redux Node/Express Ecosystem
- Redux Dev Tools
- Responsive Material-UI
- Styling Material-UI components using Styled-Components
- TaskMuncher Performance
- Transforming Html with Webpack
- Update TaskMuncher for Lighthouse Findings
- Update TaskMuncher to be a Progressive Web App
- Update TaskMuncher to use React BrowserRouter
- Update TaskMuncher to Webpack v4, Babel v7, Material-UI v3
- Upgrading Babel and ESLint to use React Advanced Language Features
- Webpack Bundle Analyzer
Taskmuncher
- Backup TaskMuncher from Digital Ocean
- Configure HTTP Nginx
- Configure HTTPS Nginx
- Configuring Google Domains
- Configuring Meta Tags
- Create Site Map
- Create SSL Certificates
- Create Ubuntu Droplet at Digital Ocean
- Deploy TaskMuncher React App to AWS
- Facebook Application Id
- First time deploy TaskMuncher React App to Digital Ocean
- Google Analytics for TaskMuncher
- Google Authentication
- Google Gmail Configuration
- Google Webmaster Tools
- Install Ubuntu Mongo
- Install Ubuntu Nginx
- Mailgun
- Maintaining Ubuntu Droplet
- Material-UI Showcase
- Optimizing TaskMuncher with Webpack 4
- React Production Issues
- TaskMuncher Images and Favicons
- TaskMuncher Overview
- TaskMuncher Performance
- TaskMuncher Website Validation
- Update SSL Certificates
- Update TaskMuncher for Lighthouse Findings
- Update TaskMuncher to be a Progressive Web App
- Update TaskMuncher to use React BrowserRouter
- Update TaskMuncher to Webpack v4, Babel v7, Material-UI v3