What are some ways to prompt electron to refresh its rendering with updated CSS?

I am currently in the process of developing my first Electron app on Windows 10, using Visual Studio Code and Git Bash as my primary tools. However, I have encountered a frustrating issue where my app has suddenly stopped updating based on css changes. Specifically, I had been experimenting with different Bootstrap form input styles for a search box. Despite reverting to a basic HTML form without any Bootstrap styling, the fancy Bootstrap input continues to appear.

Adding more text to the HTML does reflect in the app, but the moment I include a text input element, the Bootstrap style overrides everything else. I tried clearing the electron cache for my app, deleting the ~/AppData/Roaming/myapp directory, and even creating a new app in a fresh folder, yet the problem persists. I have explored solutions like those found in this discussion on Stack Overflow, but none of them seem to make a difference. At this point, I suspect there might be hidden caches either within Electron itself or possibly within Visual Studio Code and Git Bash causing this interference.

My project consists of only three files:

package.json:

{
  "name": "myapp",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  },
  "author": "",
  "devDependencies": {
    "electron": "^6.0.10"
  }
}

main.js:

const electron = require('electron');
const path = require('path');
const url = require('url');

// SET ENV
process.env.NODE_ENV = 'development';

const {app, BrowserWindow, Menu} = electron;

let mainWindow;

// Listen for app to be ready
app.on('ready', function(){

  // Create new window
  mainWindow = new BrowserWindow({});
  mainWindowURL = url.format({
    pathname: path.join(__dirname, 'mainWindow.html'),
    protocol: 'file:',
    slashes:true
  });

  mainWindow.webContents.session.clearCache(function(){})

  mainWindow.loadURL(mainWindowURL, {"extraHeaders":"pragma: no-cache\n"})
  // Quit app when closed
  mainWindow.on('closed', function(){
    app.quit();
  });

  // Build menu from template
  const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
  // Insert menu
  Menu.setApplicationMenu(mainMenu);

  // Clear cache from any previous sessions
  //mainWindow.webContents.session.clearStorageData();
  //win.once('ready-to-show', ()=>{win.show()})
  //const win = BrowserWindow.getAllWindows()[0];
  //const ses = win.webContents.session;

  //ses.clearCache(() => {});
});



// Add developer tools option if in dev
if(process.env.NODE_ENV !== 'production'){
  mainMenuTemplate.push({
    label: 'Developer Tools',
    submenu:[
      {
        role: 'reload'
      },
      {
        label: 'Toggle DevTools',
        accelerator:process.platform == 'darwin' ? 'Command+I' : 'Ctrl+I',
        click(item, focusedWindow){
          focusedWindow.toggleDevTools();
        }
      }
    ]
  });
}

mainWindow.html:

<!DOCTYPE html>
<html>
<head>
  <title>Miobium</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
  <!--<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">-->
  <!--<link rel="script" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js">-->

  <style>
    .fullPageContainer{
    }
    #left_panel {
        background-color: white;
        height: 100vh;
        float: left;
        width: 20vw;
        border-right: 1px solid grey;
    }
    #main_panel{
        background-color: white;
        height: 100vh;
        float: right;
        width: calc(78vw - 2px);
    }
    input[type=text]{
      width: 80%;
      border: 1px solid grey;
      border-radius: 4px;
    }
    </style>
</head>
<body>
    <div class="fullPageContainer">

        <div id="left_panel">
            Tags
        </div>

        <div id="main_panel">
          Search
          <form>
            <input type='text'>
          </form>
        </div>

    </div>

  <script>
    const electron = require('electron');
    const {ipcRenderer} = electron;
  </script>
</body>
</html>

Any advice or insights you can provide would be greatly appreciated! As someone new to Electron development, I am hopeful that there is a straightforward solution to resolving this issue. Thank you!

Answer №1

I finally figured out the root of my persistent issue - a bizarre coincidence that left me scratching my head.

Before the problem arose, I had been experimenting with different styles for a bootstrap search bar. The last style I tried happened to be identical to the material.css text input style. I even adjusted the bootstrap style to mirror the 'active' color used in material.css.

When I removed bootstrap and attempted to customize the styling myself, nothing changed. The input remained unchanged, leading me to believe there was some sort of caching at play. As it turns out, material.css already had the exact same style I created with bootstrap, and because material.css doesn't require special class labels for styling, I never suspected it was the culprit. Removing material.css instantly resolved the issue.

This has got to be one of the strangest bug coincidences I've ever encountered, by far.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Connect CSS Transition to a click action

Below is the code snippet. When you click on the div, it creates a folding effect to the left. You can view it here. I want to link this effect to the arrows I use for sliding back and forth. For example: The left arrow should move the slide to the l ...

Is it possible to generate distance between 2 elements without utilizing padding or margin?

In my React Native project, I'm currently working with 2 inline buttons - the search and add buttons: https://i.stack.imgur.com/tKZrf.png I'm looking to add some spacing between these buttons without impacting their alignment with the left and ...

Encountering issues while trying to deploy a Next JS 13 application on Google Cloud Platform's

Everything was functioning properly with Next version 12, however upon upgrading to Next 13 I encountered the following error. and current node version: "18.x.x" Next Js version: "13.2.1" Step #2: /app/node_modules/next/dist/build/index ...

Upon initial login, React fails to retrieve notes

I developed a note-taking React app using the MERN stack with React Router DOM v6. When I initially visit the website, I am directed to the login page as intended. However, upon logging in, the page refreshes but does not redirect to the home page. This is ...

Having trouble passing a token for authentication in Socket.IO v1.0.x?

I am currently following a tutorial on creating a token-based authentication system, which can be found here. I have implemented the following code: Code in app.html: var socket = io('', { query: "token=i271az2Z0PMjhd6w0rX019g0iS7c2q4R" }); ...

The font from the server is not displaying correctly in the local HTML file

After uploading the ttf font file to the server, I utilized the following CSS code: @font-face { font-family: "fontname"; src: url("http://www.mywebsite.com/Fonts/fontname.ttf"); } body { font-family: "fontname", sans-serif; } Within the loc ...

transferring information through POST requests in Angular and managing the data in Node.js

Recently, I was experimenting with a post request in Angular and encountered some difficulties sending data to the back-end server using Node.js. It seems like either I am not handling the data correctly on the server side or my data is not being sent in t ...

Centered on the screen are the input field and corresponding label

I am in the process of creating a signup form, and I have encountered an issue. How can I make the input wider without using a fixed width like width: 420px? Additionally, I would like to center both the input field and the label. I envision something simi ...

Having trouble running Protractor with the Angular Seed Basic app in AngularJS?

After cloning the angular-seed to my basic setup, I attempted to run protactor using the command below and encountered an error: npm run protractor npm ERR! node v5.0.0 npm ERR! npm v2.10.1 npm ERR! code ELIFECYCLE npm ERR! [email protected] protr ...

Having difficulty resolving issues with the chat box (div) scroll bar staying fixed at the bottom

I am currently working on a chat application and I am facing an issue with fixing the scroll bar at the bottom of a div when loading my PHP file. I have already written a script to achieve this, but despite accessing it using CSS Id, I am having trouble ge ...

JavaScript - A simple way to retrieve the dimensions of an image consistently

I'm currently working on a piece of Jquery code that is designed to display an image fitting within the screen's dimensions. These images are generated dynamically as needed. However, I am facing an issue where the height and width of the image a ...

Switching from using localhost:3000 to publicIP:3000 in a node.js application is a seamless process that involves updating

I'm currently using a dedicated server (Virtual Machine) with xxx.xxx.xxx.xxx as my public IP address. I want to publish my node.js application on it so that I can access it from another PC via the internet. Unfortunately, I have no clue how to do thi ...

Why aren't NavBar Image Links Functional, even though the code seems flawless? What could be the issue?

Looking at the current HTML code snippet I have within the <head> section, it includes: <ul class="nav"> <li> <a href="http://www.greg-holmes.com/#/title" target="_blank"> <img src="img/home.png"> ...

Is there a way I can add opacity to a div without impacting the other elements contained in it?

When I set the opacity of a div, it seems to affect all the other elements inside that div by making them transparent too. However, I am looking for a solution where the child elements do not inherit the opacity of their parent. Any assistance on this is ...

Commit the incorrect file name with the first letter capitalized

There seems to be an issue with the git not recognizing the correct filename casing. I have a file named User.js in my workspace, but when checking the git status, it displays user.js instead. Despite repeatedly changing and committing as User.js, the gi ...

Using NodeJS to extract information from Opendata JSON files

I'm currently working on a project that involves fetching JSON data from an Open Dataset using NodeJS and passing it to angular. The challenge I'm facing is that I'm receiving a JSON file instead of a JSON object, which makes it difficult to ...

Styling <CardHeader> component with React and Material UI CSS

Incorporating React and Material UI, my goal is to arrange 3 divs within a <Card> <CardHeader/>, positioning them with left, center, and right alignment as illustrated below. The modification required is minor - I simply need to eliminate the ...

Express.js receiving JSON POST data with AngularJS incorrectly interpreted as keys instead of values

I am facing an issue while trying to make a POST request with JSON data from angularjs to node/express. The problem is that all the data is appearing in the KEY of the req.body instead of as key value pairs. Although I found a similar question addressing ...

Turn off the extra space inserted by DataTables

Help needed with centering table header text. <table class="table table-bordered table-hover center-all" id="dataTable"> <thead> <tr> <th scope="col" style="text-align: center">Nam ...

Error receiving parameter in express route callback function

At the moment, I have been working with a number of routes in Express. Some routes are quite lengthy and tend to look like this: router.get('/api/comments', function(req, res, next){ Comment.find({"user": req.payload._id}).exec(function(err,co ...