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

Hot Module Replacement (HMR) Integration #1265

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

minowau
Copy link
Contributor

@minowau minowau commented Jul 14, 2024

solving issue #1255

This project implements Hot Module Replacement (HMR) for a React-based Chrome extension, allowing developers to see real-time changes in their popup component without needing to refresh the entire extension. The following outlines the configuration and structure necessary for achieving this setup.

Key Components

  1. Webpack Configuration (webpack.config.js):

    • Configures Webpack for development and production modes, specifying the entry point and output settings.
    • Enables HMR in the development server for instant updates.
  2. Entry Point (src/popup.js):

    • Contains the main logic for the popup component, integrating the HMR logic to allow for module updates without a full reload.
  3. Index File (src/index.js):

    • Updated to support HMR with checks for module.hot, ensuring that the component re-renders on updates without refreshing the entire popup.
  4. Package Configuration (package.json):

    • Includes scripts for building and serving the application, specifying configurations needed for both development and production.
  5. Development Server:

    • The command npm start launches a development server with HMR enabled, providing a smooth development experience.

Summary of Changes

  • HMR Logic:

    • Added in popup.js using if (module.hot) { ... } to ensure updates are reflected in real-time.
    • Implemented in index.js to facilitate automatic re-rendering of the popup component on code changes.
  • Webpack Dev Server: Configured with hot: true to support HMR functionality.

  • File Structure: Organized files into a clear structure, facilitating maintainability and ease of access.

Benefits

Implementing HMR improves the development workflow by reducing the time spent on refreshing and waiting for the extension to reload. This results in a more productive environment, allowing for faster iteration and debugging of features.

✨ Pull Request

📓 Referenced Issue

ℹ️ About the PR

🖼️ Testing Scenarios / Screenshots

solving issue responsively-org#1255

This project implements Hot Module Replacement (HMR) for a React-based Chrome extension, allowing developers to see real-time changes in their popup component without needing to refresh the entire extension. The following outlines the configuration and structure necessary for achieving this setup.

#### Key Components

1. **Webpack Configuration (`webpack.config.js`)**:
   - Configures Webpack for development and production modes, specifying the entry point and output settings.
   - Enables HMR in the development server for instant updates.

2. **Entry Point (`src/popup.js`)**:
   - Contains the main logic for the popup component, integrating the HMR logic to allow for module updates without a full reload.

3. **Index File (`src/index.js`)**:
   - Updated to support HMR with checks for `module.hot`, ensuring that the component re-renders on updates without refreshing the entire popup.

4. **Package Configuration (`package.json`)**:
   - Includes scripts for building and serving the application, specifying configurations needed for both development and production.

5. **Development Server**:
   - The command `npm start` launches a development server with HMR enabled, providing a smooth development experience.

#### Summary of Changes

- **HMR Logic**:
  - Added in `popup.js` using `if (module.hot) { ... }` to ensure updates are reflected in real-time.
  - Implemented in `index.js` to facilitate automatic re-rendering of the popup component on code changes.

- **Webpack Dev Server**: Configured with `hot: true` to support HMR functionality.

- **File Structure**: Organized files into a clear structure, facilitating maintainability and ease of access.

### Benefits

Implementing HMR improves the development workflow by reducing the time spent on refreshing and waiting for the extension to reload. This results in a more productive environment, allowing for faster iteration and debugging of features.
@CLAassistant
Copy link

CLAassistant commented Jul 14, 2024

CLA assistant check
All committers have signed the CLA.

@minowau
Copy link
Contributor Author

minowau commented Jul 14, 2024

@manojVivek I hope this would solve your doubts.And you can check my code as well.I hope u star it

import React, {useMemo, useState, useEffect, useRef} from 'react';
import {Rnd} from 'react-rnd';
import {useSelector, useDispatch} from 'react-redux';
import React, { useMemo, useState, useEffect, useRef } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the purpose of these changes in the legacy app?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would give an simplified version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better understanding

Copy link
Collaborator

Choose a reason for hiding this comment

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

@minowau We don't actively do any development on the legacy app. So, for the sake of clean git history, can you please revert these changes so that we can merge the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I am reverting those

@violetadev
Copy link
Contributor

I tested it and the reloading is faster when you change any css :)

@minowau
Copy link
Contributor Author

minowau commented Aug 3, 2024

Can U merge the pull request

@minowau minowau requested a review from violetadev August 3, 2024 20:02
@minowau
Copy link
Contributor Author

minowau commented Aug 5, 2024

it is not possible to revert from my side as there is only one commit can u merge the pull request as there will be no visible change but just a shortening of code. Or u can change it after merging.

@violetadev
Copy link
Contributor

@minowau in your branch you can do:
git checkout origin/main path-to-file and it will make that file be the same as main. Then you add it to a new commit normally and you’re good to go

@minowau
Copy link
Contributor Author

minowau commented Aug 5, 2024

oh thanks for the help I forgot

@minowau
Copy link
Contributor Author

minowau commented Aug 6, 2024

I tried it but It

@minowau in your branch you can do: git checkout origin/main path-to-file and it will make that file be the same as main. Then you add it to a new commit normally and you’re good to go

I tried but I was not able to do it. If U can help U can have my credentials and U can try or U CAN JUST MERGE IT and change it afterwards with an other pull it is just a one line code

@violetadev
Copy link
Contributor

I tried it but It

@minowau in your branch you can do: git checkout origin/main path-to-file and it will make that file be the same as main. Then you add it to a new commit normally and you’re good to go

I tried but I was not able to do it. If U can help U can have my credentials and U can try or U CAN JUST MERGE IT and change it afterwards with an other pull it is just a one line code

don't give your credentials to anyone please. Can you do from the root of the project git checkout origin/main desktop-app-legacy/app/components/LiveCssEditor/index.js ? what does it say when you do that?

@minowau
Copy link
Contributor Author

minowau commented Aug 6, 2024

I tried it but It

@minowau in your branch you can do: git checkout origin/main path-to-file and it will make that file be the same as main. Then you add it to a new commit normally and you’re good to go

I tried but I was not able to do it. If U can help U can have my credentials and U can try or U CAN JUST MERGE IT and change it afterwards with an other pull it is just a one line code

don't give your credentials to anyone please. Can you do from the root of the project git checkout origin/main desktop-app-legacy/app/components/LiveCssEditor/index.js ? what does it say when you do that?

It is giving a fatal error once review the changes it was just adding a place in the brackets so there would be no problem

@minowau
Copy link
Contributor Author

minowau commented Aug 6, 2024

it just gives the code a better look but no changes were done withe the change in the location of words in the brackets.Sorry but I tried but it didn't work on my side

@violetadev violetadev merged commit 6affc07 into responsively-org:main Aug 6, 2024
4 checks passed
@minowau
Copy link
Contributor Author

minowau commented Aug 6, 2024

can u add me as a contibutor

@violetadev
Copy link
Contributor

@all-contributors Please add @minowau for code.

Copy link
Contributor

@violetadev

I've put up a pull request to add @minowau! 🎉

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.

None yet

4 participants