Why does Vite automatically insert tags for images and how can I disable or control it?

I’m using Vite + React with both SSR and SPA builds.
When I run the dev server or build for production, Vite automatically injects image preload tags like this:

<div id="root">
  <link rel="preload" as="image" href="/images/geonix-logo.svg">
  <div>...</div>
</div>

I never manually added these preload links anywhere in my code (not in index.html, not in React components).

What I checked:

  • These tags are not in index.html.

  • They are not imported or rendered manually in any components.

  • I searched the entire codebase for image preload links (<link rel="preload" as="image">), but couldn’t find any in the source. They only appear in the build output.

    • he same happens in both dev and production builds.

    • It occurs consistently with any image used in React components.

      .⚡ Temporary workaround I tried

      As a temporary fix, at the stage of sending the final SSR HTML,
      I extract these image preload tags from inside the root, remove them, and then insert them manually into the <head> before sending the response.

      This works but doesn’t feel like the best solution.

      My Vite config

      import { defineConfig, loadEnv } from "vite";
      import react from "@vitejs/plugin-react-swc";
      import path from "node:path";
      import { getProxyOptions } from "./server/proxy/getProxyOptions.js";
      
      export default defineConfig(({ mode, isSsrBuild }) => {
        const isDev = mode === "development";
        const isSpa = process.env.SPA === "true";
      
        const env = loadEnv(mode, process.cwd(), "REACT_APP_");
        const defineEnv = Object.entries(env).reduce((acc, [key, val]) => {
          acc[`process.env.${key}`] = JSON.stringify(val);
          return acc;
        }, {});
        const proxyOption = getProxyOptions(env);
      
        return {
          root: isSpa ? path.resolve(__dirname, "spaRoot") : path.resolve(__dirname, "."),
          plugins: [react()],
          publicDir: path.resolve(__dirname, "public"),
          define: defineEnv,
          build: {
            minify: "esbuild",
            sourcemap: false,
            cssMinify: true,
            copyPublicDir: !isSsrBuild,
            rollupOptions: { output: { manualChunks: undefined } },
          },
          ssr: isDev ? {} : {
            noExternal: [/^@forproxyband/main-ui-kit/, "classnames", "lodash", "uuid"],
          },
          server: {
            proxy: proxyOption && isDev ? { "/api": proxyOption } : undefined,
          },
          resolve: {
            alias: {
              "@": path.resolve(__dirname, "src"),
              "/src": path.resolve(__dirname, "src"),
            },
          },
        };
      });
      
      

      My questions

      1. Where exactly do these image preload tags come from in Vite’s runtime?

      2. How can I disable or control this behavior (e.g. disable image preloads or move them to the <head>)?

      3. Why are they inserted inside the #root element instead of the <head>?

Image won’t display in jsp page if inside tags

I have this block of code in a jsp page:

<script type="application/javascript">
    $(document).ready(function () {
        $('a.hide').click(function(e){
            e.preventDefault();
            if ($(this).parents('.arrears-notification').length) {
                $('.arrears-notification').hide();
            }
        });
    });
</script>

<div class="arrears-notification">
    <div style="display:flex;align-items:center;">
        <div class="col-md-12">&nbsp;</div>
    </div>
    <div style="display:flex;align-items:center;">
        <div>&nbsp;</div>
        <div style="border:2px solid #BEBEBE;border-radius:5px;padding:10px;margin: 0 auto;width:95%">
            <img src="https://link/to/image1.svg" style="width:24px;height:24px;">
            <c:out value='<b>Your ${ account.entries[0].accountType } is at risk.</b> Make a card payment now to keep your account active.&nbsp;<a href="/payment/payment.form" id="lnkPremium_Arrears">Clear your arrears.</a>' escapeXml="false" />
            <a class="hide" href="#"><img src="https://link/to/image2.svg" style="width:24px;height:24px;float:right;"></a>
        </div>
        <div>&nbsp;</div>
    </div>
    <div style="display:flex;align-items:center;">
        <div class="col-md-12">&nbsp;</div>
    </div>
</div>

If image2 is clicked, the entire div block should be hidden. This works when I paste the code into https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_editor. However, when I run my application, image2 doesn’t display. It does display if I remove the <a> tags surrounding <img src="https://link/to/image2.svg" style="width:24px;height:24px;float:right;">. What’s wrong here and how do I get this to display in my jsp?

Is getImageData() broken in Javascript, and what can I do to fix it?

The getImageData() function for the Canvas appears to have ceased to work. As in, the program doesn’t recognise it as a function call.
Here’s the code I’ve been working on:

<canvas id="myCanvas"></canvas>
<img id="myImage" src="image.png" hidden="true" onload="
    let canv = document.getElementById('myCanvas');
    let cnxt = canv.getContext('2d');
    let img = document.getElementById('myImage');
    cnxt.drawImage(img,0,0);
        //    up to here it works fine; the problem is with the next line
    let imgData = cnxt.getImageData(0,0,canv.width,canv.height);
    alert(imgData.data.length);
        //    no alert happens; the command to .getImageData() halts the program
" />

I’m using Google Chrome on Windows, but the same thing happens when I use Microsoft Edge. I’m hosting locally on Xampp and yes, the images are stored in the same folder as the html page. I have tried specifying crossOrigin="anonymous" in the <img> tag, as well as permutations with different capitalization of the words; this causes drawImage() to cease to function as well.

What’s really strange is that when I open projects I wrote a few months ago, which also depend on getImageData() and were working fine then, they too have ceased to function.

What’s going on and what can I do?

Converting React native component into html

I want to use the react-native-html-to-pdf module to create a pdf out of my react-native-gifted-charts components.

Image of a LineChart

Example of the line chart code below

<LineChart 
  hideRules
  data={lineData}
  color={colors.text} 
  height={verticalScale(300)}
  textColor={colors.fieldText}
  xAxisLength={width - horizontalScale(90)}
  spacing={horizontalScale(23)}
  xAxisColor={colors.fieldText}
  yAxisColor={colors.fieldText}
  dataPointsColor={colors.text}
  yAxisTextStyle={{color: colors.fieldText, fontWeight: 700}}
  xAxisLabelTextStyle={{
   color: colors.fieldText, 
   fontSize: moderateScale(12), 
   fontWeight: 700
  }}
/>

How can I turn this component or any react native component into plain html so that i can use it in RNHTMLtoPDF?

I tried using renderToStaticMarkUp but it did not display the chart.

Requesting HTML of open loaded page (with infinite scrolling) in Python without Selenium [closed]

I’m trying, for no reason at all but personal satisfaction, to scrape some websites that have infinite scrolling using Python (I guess they work with JavaScript, but I don’t know what it is, that’s what I’m guessing from consulting lots of pages on this website — Instagram is the website I was trying on, with public profiles, but it’s the same as like YouTube).
I do not want to use Selenium, as I don’t know what it does and I don’t know if I can trust it — and I don’t know a lot of things about it.
I can manage to get to a certain page and load it as far down as I want using Python, but I cannot seem to be able to get the HTMLs of the page from which I could get all the content inside the page (excuse me if I’m saying something incorrect, I’m not an expert at all about this). At least, that’s what I think is an HTML: the working code for limited data (due to not loading the page) works with command “httpx.Client().get({url})” from “import httpx” and gets processed with “json.loads()” from “import json”.

What I would need right now is something to replace Selenium’s command “{webdriver.Firefox().}page_source” from which I’d obtain stuff to be parsed with beautifulsoup4. I also cannot use Selenium because when I execute the code the browser opens in another way (not with Selenium’s webdriver, that seems to cause me some problems) (I also cannot find Selenium’s source code).

Otherwise, I would need something (most likely something like a “get” request) to get stuff from the page that I loaded, that would then be processed with “json.loads()” from “import json” (I have a working code that extracts stuff from a page using json.loads(), but I have limited amount of data since the “get” request that I’m using doesn’t load the full page).

Using “requests_html” doesn’t work for me: I cannot seem to be able to install Chromium on my pc, and I keep having problems with “async” functions (that I don’t know what are there for).

I wanna emphasise that the page that I want to extract data from is already open and fully loaded (at least to a point where I’m satisfied with the amount of content) in a Firefox window.

Can anyone help me? I haven’t seen an updated discussion about this, latest (few) ones are from at least a year ago; most of them are from way back (around 2014-2018, and they talk about modules that are not kept up to date anymore).

Requesting HTML of open loaded page (with infinite scrolling) in Python without Selenium

Good evening,

I’m trying, for no reason at all but personal satisfaction, to scrape some websites that have infinite scrolling using Python (I guess they work with JavaScript, but I don’t know what it is, that’s what I’m guessing from consulting lots of pages on this website — Instagram is the website I was trying on, with public profiles, but it’s the same as like YouTube).
I do not want to use Selenium, as I don’t know what it does and I don’t know if I can trust it — and I don’t know a lot of things about it.
I can manage to get to a certain page and load it as far down as I want using Python, but I cannot seem to be able to get the HTMLs of the page from which I could get all the content inside the page (excuse me if I’m saying something incorrect, I’m not an expert at all about this). At least, that’s what I think is an HTML: the working code for limited data (due to not loading the page) works with command “httpx.Client().get({url})” from “import httpx” and gets processed with “json.loads()” from “import json”.

What I would need right now is something to replace Selenium’s command “{webdriver.Firefox().}page_source” from which I’d obtain stuff to be parsed with beautifulsoup4. I also cannot use Selenium because when I execute the code the browser opens in another way (not with Selenium’s webdriver, that seems to cause me some problems) (I also cannot find Selenium’s source code).

Otherwise, I would need something (most likely something like a “get” request) to get stuff from the page that I loaded, that would then be processed with “json.loads()” from “import json” (I have a working code that extracts stuff from a page using json.loads(), but I have limited amount of data since the “get” request that I’m using doesn’t load the full page).

Using “requests_html” doesn’t work for me: I cannot seem to be able to install Chromium on my pc, and I keep having problems with “async” functions (that I don’t know what are there for).

I wanna emphasise that the page that I want to extract data from is already open and fully loaded (at least to a point where I’m satisfied with the amount of content) in a Firefox window.

Can anyone help me? I haven’t seen an updated discussion about this, latest (few) ones are from at least a year ago; most of them are from way back (around 2014-2018, and they talk about modules that are not kept up to date anymore).

Thank you in advance.

I cannot implement new code into existing code [closed]

I am trying to make a web card game with my limited programming knowledge and the help of AI.

The problem is that I was iterating on the code (index.html) but I did not like the styles of the card variants, so I tried to make them separately (showcase-effects.html) until I ended up liking them.

The thing is, no matter how hard I try to integrate the code from showcase-effects.html into the main index.html, I end up breaking everything.

I’ve tried changing the last function to showcase-effects.html, but it doesn’t work properly or it breaks the animations, glow or album. The effects themselves don’t transfer properly to index.html neither.

I’ve made sure to change the function calls when deleting/changing functions (all 15 times, haahhahha), but nothing truly works 🙁

Both htmls are in my githu repo: https://github.com/D6ni/FootballTCG

Having 3 buttons at the same height

This might be something really simple and I’m just complicating things for myself. Tried multiple things and wasn’t able to accomplish the following:

I have 3 columns (cards) with text and a button underneath. The middle one has a hover functionality, where it shows a when hovered over.
The problem? The buttons don’t align horizontally. I’d like them to be at the same level. How do I align the 3 buttons without changing other components?
I know I can just bottom:240px; but what if I don’t know the specific height?

Here is the relevant part of the code:

        <!-- 1) Café-Concert & more -->
        <article class="card">
          <div class="card-body">
            <h3>Café-Concert & more</h3>
            <p class="card-text">A lot of text</p>
          </div>
          <div class="card-actions mt-3">
            <a class="btn" href="mailto:{{email}}?subject=Offer%20request%20%E2%80%94%20Caf%C3%A9%E2%80%91Concert">
              Get an offer
            </a>
          </div>
        </article>

        <!-- 2) Lectures & workshops -->
        <article class="card reveal-list">
          <div class="card-body">
            <h3>Lectures &amp; Workshops</h3>
            <p class="card-text">A lot of text</p>
          </div>
          <div class="card-actions mt-3">
            <a class="btn" href="mailto:{{email}}?subject=Offer%20request%20%E2%80%94%20Lecture%20%26%20Workshop">
              Get an offer
            </a>
          </div>
          <ul class="mt-2">
            <li>What is HIP: history, milestones, where we are now.</li>
            <li>
              Building blocks of HIP: sources, instruments, articulation, tempo,
              ornamentation, continuo.
            </li>
            <li>
              The early keyboard family: harpsichord, spinet, clavichord, square
              piano.
            </li>
            <li>National styles: England, France, Germany, Italy.</li>
            <li>
              Basso continuo, from figures to music, with singers or
              instrumentalists.
            </li>
            <li>
              Tailored sessions: happy to adapt topics or combine lecture and
              workshop in one visit.
            </li>
          </ul>
        </article>

        <!-- 3) Consultation -->
        <article class="card">
          <div class="card-body">
            <h3>Consulting & Coaching</h3>
            <p class="card-text">A lot of text</p>
          </div>
          <div class="card-actions mt-3">
            <a class="btn" href="mailto:{{email}}?subject=Offer%20request%20%E2%80%94%20Consultation">
              Get an offer
            </a>
          </div>
        </article>
      </section>


/* Cards, grids */
.grid {
  display: grid;
  gap: 16px;
}
.cards-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  align-items: stretch; /* ensure grid items fill row height */
}

.card {
  background: #fff;
  border: 1px solid var(--border, #ece7de);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.03);
  display: flex; /* key */
  flex-direction: column; /* key */
}
.card h3 {
  margin: 0 0 8px;
  font-size: 16px;
}
.card p {
  margin: 0;
  color: #555;
  font-size: 14px;
}

.card-actions {
  margin-top: auto; /* pushes this block to the bottom */
  text-align: center; /* center the button horizontally */
}
.card-actions .btn {
  display: inline-block; /* keeps the button sized nicely when centered */
}

.reveal-list ul {
  max-height: 0; /* hide the list */
  overflow: hidden;
  opacity: 0;
  transform: translateY(-4px);
  margin-top: 0; /* override .mt-2 while hidden */
  transition: max-height 0.35s ease, opacity 0.25s ease, transform 0.35s ease,
    margin-top 0.2s ease;
}

/* Show when the card is hovered (mouse) or focused (keyboard/tab) */
.reveal-list:hover ul,
.reveal-list:focus-within ul {
  max-height: 600px; /* big enough to contain the list */
  opacity: 1;
  transform: translateY(0);
  margin-top: 8px; /* restore spacing when open */
}

Facebook stylex react native

According to library authors https://stylexjs.com/blog/introducing-stylex/ this should work as well in web as in react native:

We created StyleX not only to meet the styling needs of React developers on the web, but to unify styling for React across web and native.

The problem is that i am unable to make it work in react native. I have library installed, I have added “@stylexjs/babel-plugin” to plugins array in babel.config.js and in the src/components/button I have code

import { Pressable, Text } from "react-native";
import * as stylex from "@stylexjs/stylex";

export const styles = stylex.create({
  button: {
    backgroundColor: "#00FFFF",
    fontSize: 24,
    height: 50,
  },
  text: {
    color: "#663399",
  },
});

type Props = {
  children: string;
};

export const Button = ({ children }: Props) => {
  console.log(stylex.props(styles.button));
  return (
    <Pressable style={stylex.props(styles.button).style}>
      <Text {...stylex.props(styles.text)}>{children}</Text>
    </Pressable>
  );
};

console.log produces this output: {“className”: “x1lt72u0 x1pvqxga x10wjd1d”}
so clearly it is working, just not the way react native would expect stylex.props(styles.button).style returns undefined, if someone knows how to make stylex work in react native i would higly appreciate some help here. And how on earth there is nothing about react native in the documentation. Its facebooks product! 🙁
I oult not fined any mentions on stylex github discusions, maybe stylex does not work in react native after all? ;p Thanks for any help.

React useEffect causing infinite re-render when updating state from async call [closed]

We are developing a React application for our company. In one of our components, we are fetching data from an API inside useEffect and updating the state. But the component goes into an infinite re-render loop, and the browser slows down.

I tried changing the dependency array to [], but then the API didn’t re-fetch when the filter changed.
I also tried moving the fetch function outside the useEffect, but it still caused unwanted renders.
I expect the API call to run only once when the component mounts and again only when the filter value changes.

Infinite CSS/JS image carousel using swipe left/swipe right and large number of images

I want to create a static image gallery with a carousel that can be used with swipe left/swipe right gestures.

Currently I have a scrollable view that uses the scroll-snap features of CSS. It works like intended, but has an optical issue.

As the number of images can get fairly large, I have an ugly scroll effect when directly jumping to a certain image by clicking on a thumbnail. AFAIK there is no other way than using scroll()/scrollTo()/etc. to set the viewport of the carousel to a certain position.

While thinking about a workaround, I had the idea to create 3 scrollable <div> elements and combine them to an infinite scroller. They will have a fixed size to avoid the ugly scroll effect, and to not have a huge horizontal view with a large number of images. The hidden <div> elements will be preloaded with the next/previous images in the background and are shown when the user reaches the end of the currently visible <div>.

What do you think about this? Does this sound sensible? I’m not an expert regarding CSS/JS, just learning and trying to create things I want to have.

How to download a file in JavaScript without using anchor tag download attr? [duplicate]

I need to download a file to the user without using the <a download></a> hack, but am unable to find an alternative method. Basically, with this method, it just downloads the file without the “Save as” file prompt showing up. I want the “Save as” file dialog to show up so that the user can rename the file or pick which folder it should be in.

Without asking the user to change their settings, how can this be done? I’ve seen this done in many web apps, so I know it’s possible, but many web searches and Stack Overflow searches return nothing useful.