Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log-viewer-webui: Add boilerplate React client. #468

Merged
merged 13 commits into from
Jul 5, 2024

Conversation

kirkrodrigues
Copy link
Member

Description

Following #442, this PR adds a boilerplate client written using React.

For consistency, the server's package.json was also changed to:

  • Rename the package to log-viewer-webui-server
  • Change the dev-server target to npm run watch

Validation performed

  • Validated npm lint:check passes.
  • Validated npm run watch starts a local HTTP server that keeps track of source changes.
  • Validated npm run build builds a bundle in dist that can be served with npx http-server dist

@kirkrodrigues kirkrodrigues requested a review from junhaoliao July 3, 2024 10:48
Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it looks good to me. There are some devDependencies that are specified but I do not see the usages of those in the webpack config file. If those are to be configured later, can we submit those another PR?

"lint:check": "npx eslint --no-eslintrc --config package.json src webpack.config.js",
"lint:fix": "npx eslint --fix --no-eslintrc --config package.json src webpack.config.js",
"build": "webpack --define-process-env-node-env production",
"watch": "webpack serve"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, can we rename this config as start? Let's continue the discussion in server/package.json.

"version": "0.1.0",
"description": "",
"main": "src/main.js",
"scripts": {
"dev": "NODE_ENV=development nodemon src/main.js",
"lint:check": "npx eslint --no-eslintrc --config package.json src",
"lint:fix": "npx eslint --fix --no-eslintrc --config package.json src",
"start": "NODE_ENV=production node src/main.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to rename this script as prod and the one below for development as start? That way we will be consistently using start as the name for all development scripts across all repos.

"@babel/preset-env": "^7.24.7",
"@babel/preset-react": "^7.24.7",
"@webpack-cli/generators": "^3.0.7",
"autoprefixer": "^10.4.19",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems handy, but it seems not only we need to configure "browserslist" in this package.json file but also we need to install postcss and add some related config in webpack.config.js according to their docs: https://github.com/postcss/autoprefixer#webpackhttps://github.com/postcss/autoprefixer#webpack
(Did I miss anything? )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I did have postcss initially, but had some issues so I removed it but forgot to remove this.

Comment on lines 17 to 18
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-transform-runtime": "^7.24.7",
Copy link
Member

@junhaoliao junhaoliao Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see those getting configured in webpack.config.js. Mind sharing what the usages are of those?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didn't clean up package.json properly.

"@babel/plugin-transform-runtime": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"@babel/preset-react": "^7.24.7",
"@webpack-cli/generators": "^3.0.7",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto - why do we need this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we just need "webpack-cli": "^5.1.4",?

"eslint-config-yscope": "latest",
"html-webpack-plugin": "^5.6.0",
"mini-css-extract-plugin": "^2.9.0",
"prettier": "^3.3.2",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add a config file for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

];

const config = {
devtool: isProduction ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the devServer config to be added in a future PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I read the docs incorrectly, but it seemed like the defaults worked?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the defaults do work, but do we want to be explicit about which port to use? Also, similar to HMR, do we want to enable "Fast Refresh" with https://github.com/pmmmwh/react-refresh-webpack-plugin ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I think the port defaults to 'auto' which seems like it would be more flexible than specifying it explicitly (and the CLI prints out what it chose).
  • We could add open if you like (I prefer not automatically opening the browser, but that's just me).
  • What does that plugin do compared to the default dev server?

Copy link
Member

@junhaoliao junhaoliao Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the port defaults to 'auto' which seems like it would be more flexible than specifying it explicitly (and the CLI prints out what it chose).

Gotcha. Let's leave it as is then.

We could add open if you like (I prefer not automatically opening the browser, but that's just me).

I don't have a preference so I'm fine leaving it as false.

What does that plugin do compared to the default dev server?

It's for preserving states of any modified React components. e.g. Say we are modifying a button in a modal window, with conventional HMR the modal window will be closed when the page auto reloads. With Fast Refresh, the modal window will remain open without us clicking again in the browser. Another example is with Fast Refresh, any existing text input is preserved in a text field when the page auto reloads.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, thanks.

},
output: {
path: path.resolve(dirname, "dist"),
filename: "[name].[contenthash].bundle.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contenthash has been causing issues with HMR / Fast Refresh in my experience and I recommend removing such in a dev environment setting.

Suggested change
filename: "[name].[contenthash].bundle.js",
filename: isProduction?
"[name].[contenthash].bundle.js":
"[name].bundle.js",

@kirkrodrigues kirkrodrigues requested a review from junhaoliao July 4, 2024 21:05
components/log-viewer-webui/client/package.json Outdated Show resolved Hide resolved
"version": "0.1.0",
"description": "",
"main": "src/main.js",
"scripts": {
"dev": "NODE_ENV=development nodemon src/main.js",
"prod": "NODE_ENV=production node src/main.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's alphabetize these.

docs/src/dev-guide/components-log-viewer-webui.md Outdated Show resolved Hide resolved
docs/src/dev-guide/components-log-viewer-webui.md Outdated Show resolved Hide resolved
@kirkrodrigues kirkrodrigues requested a review from junhaoliao July 5, 2024 02:29
@kirkrodrigues kirkrodrigues requested review from junhaoliao and removed request for junhaoliao July 5, 2024 05:00
Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. The PR title is fine for the squashed commit message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants