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

Having difficulty running strapi and react at the same time

I encountered issues when attempting to run both strapi and react concurrently in the public directory of strapi. [1] npm ERR! code ELIFECYCLE [1] npm ERR! errno 1 [1] npm ERR! [email protected] start: `react-scripts start` [1] npm ERR! Exit status ...

I'm encountering a Type Error message in VS Code terminal stating that converting data to string is not a function. Can someone please help me understand this type error? I am new to Node.js and

const fileSystem = require('fs'); const data = fileSystem.readFileSync('example.txt'); if (data) console.log(data.toString()); console.log('Program Ended'); This is the code I wrote: and this is the error message my terminal ...

Unable to implement a transition to adjust the scaling transformation

As I work on developing a website for a local business, my progress involves creating a menu bar. However, I am facing an issue with the transition I have applied using transform: scale(1.2) which does not seem to be working as intended. After spending h ...

"The combination of Windows, @font-face, and Cyrillic characters presents a

I am encountering an issue with font-face and Cyrillic characters. The fonts display properly in any browser on OS X, but fail to render on a Windows 7 machine (chrome, ie etc). Even after putting the fonts through Font Squirrel and testing the demo files ...

What is the best way to position a button directly to the right of a text box with no space in

Is there a way to perfectly align a submit button to the right of a text or search box, matching the height of the search box, and eliminating any unwanted white space between them? This is my current setup: <input type="text" value="" placehold ...

Step-by-step guide on utilizing Create React App for installing React:

Hey there, I'm completely new to React and I'm struggling with the installation process. I've downloaded Node.js and have versions v12.18.3 and NPM 6.14.6 installed on my system. However, whenever I try to follow the create-react-app install ...

Troubleshooting: Image Not Displaying in Twitter Bootstrap Theme

I'm new to using bootstrap and I'm encountering an issue where my image is not showing up. Strangely, the default background image is appearing even though I have not referenced it in the HTML or CSS files. View my code here ...

What is the best way to conceal a sticky footer using another element?

I have a footer that remains fixed at the bottom of both long and short pages. Below is the CSS code for this footer: .footer{ position: absolute; bottom: 0; width: 100%; height: 100px; background-color: white; } My goal is to achieve a 'r ...

The readStream in Node.JS unexpectedly terminates before the writeStream

I'm currently working on a project that involves fetching PDF files from remote servers and immediately sending them back to the clients who made the request. Here is the code snippet I am using: var writeStream = fs.createWriteStream(filename); writ ...

Tracking the usage of apps and monitoring the opened files can be achieved through nodejs

As I plan for an upcoming project, my goal is to track user activity in order to monitor their productivity levels. I am particularly interested in being able to identify which file a user has open in applications like Adobe Photoshop and detect when they ...

Using the componentDidMount() method for server-side rendering

Struggling to optimize the performance of my webpage by server-side rendering, I've encountered an issue where the componentDidMount() lifecycle method of my page's components is not being called. Take a look at my primary template file: import ...

A guide on compiling Sass without using gulp and Laravel Elixir [SOLUTION]

If you encounter an error similar to this one: https://i.stack.imgur.com/ZqVeV.png You have come to the right place :) ...

Unable to download ember-cli using npm

After completely removing node from my Windows machine and deleting all associated node and npm folders, I proceeded to reinstall: node (v0.12.7) npm (3.0.0) python (2.7.10) However, upon installing ember-cli, the following error message appeared: PS C ...

When attempting to parse a file name using a regular expression in TypeScript (or even plain Node.js), the unexpected outcome is a

Looking to extract language information from a filename? Check out this simple construct: The structure of my language.ts model is as follows: export interface Language { language?: string; region?: string; } The function designed for parsing the fi ...

Is storing HTML tags in a database considered beneficial or disadvantageous?

At times, I find myself needing to modify specific data or a portion of it that originates from the database. For instance: If there is a description (stored in the DB) like the following: HTML 4 has undergone adjustments, expansions, and enhancements b ...

Endless loop issue while redirecting within getInitialProps in Next.js

I recently started using Next.js and encountered an issue with getInitialProps in my _app.jsx file. I am facing an infinite loop error but unsure of the reason behind it. Can someone please explain why this is happening and suggest ways to resolve it? co ...

Attempting to modify a singular document within mongodb by leveraging node.js

const modifyTask = async (req, res) => { const { id } = req.params; let update = {}; if (req.body.taskTitle) update.taskTitle = req.body.taskTitle; if (req.body.taskContent) update.taskContent = req.body.taskContent; if (req.body.role) update. ...

How can one safeguard their JavaScript code from potential threats and unauthorized access?

How can I ensure that a web app is not accessible or operated from the local file system? The app has a custom front-end workspace created with JS and various libraries, which should only be usable when the user is logged in to the domain with an active i ...

Upon refreshing the page, an inline script was not executed due to its violation of the Content Security Policy directive: "script-src 'self'"

When I refresh the page on my production build for all routes except "/", I encounter an error in my Node/React app which results in a blank page being displayed. The error message states: "Refused to execute inline script because it violates the followi ...

Serve the same variable page in Node.js Express without the need for URL parameters

Currently, I'm working on a project in Node.js where I need to serve a single page based on a value that the user passes in. Instead of using URL parameters like site.com/page?var=value, I prefer the URLs to look like site.com/value. At the moment, I ...