JavaScript not finding css-variables – darkmode toggle in WordPress (webflow conversion)

I have an issue with my WordPress website and some custom JavaScript I want to use. The code gets loaded into the site with this script tag on line 16 in the head-section:

<script tr-color-vars="text,background,button-background,button-text,background-50,nav-menu-link,toggle-bg,toggle-offset"
duration="0.5" ease="power1.out"
src="https://cdn.jsdelivr.net/gh/timothydesign/[email protected]/dark-mode-toggle.js">

‘tr-color-vars’ lists the variables I’d like to change between light and dark-mode. ‘src=’ calls the cdn-hosted code.

In my webflow website, where I converted the theme from, the toggle works fine.

On the WordPress site, the code from the script returns the error-message:

No variables found matching tr-color-vars attribute value

Yet the variables are there.

Why does the js-code not find the variables? Any hint would be much appreciated.

live webflow site (working example)

link of wordpress site (toggle issue)

I got this code and the how-to from timothy ricks on YouTube: Tutorial

JavaScript code:

/**
 * Dark Mode Toggle 1.0.2
 * Copyright 2023 Timothy Ricks
 * Released under the MIT License
 * Released on: November 28, 2023
 */

function colorModeToggle() {
  function attr(defaultVal, attrVal) {
    const defaultValType = typeof defaultVal;
    if (typeof attrVal !== "string" || attrVal.trim() === "") return defaultVal;
    if (attrVal === "true" && defaultValType === "boolean") return true;
    if (attrVal === "false" && defaultValType === "boolean") return false;
    if (isNaN(attrVal) && defaultValType === "string") return attrVal;
    if (!isNaN(attrVal) && defaultValType === "number") return +attrVal;
    return defaultVal;
  }

  const htmlElement = document.documentElement;
  const computed = getComputedStyle(htmlElement);
  let toggleEl;
  let togglePressed = "false";

  const scriptTag = document.querySelector("[tr-color-vars]");
  if (!scriptTag) {
    console.warn("Script tag with tr-color-vars attribute not found");
    return;
  }

  let colorModeDuration = attr(0.5, scriptTag.getAttribute("duration"));
  let colorModeEase = attr("power1.out", scriptTag.getAttribute("ease"));

  const cssVariables = scriptTag.getAttribute("tr-color-vars");
  if (!cssVariables.length) {
    console.warn("Value of tr-color-vars attribute not found");
    return;
  }

  let lightColors = {};
  let darkColors = {};
  cssVariables.split(",").forEach(function (item) {
    let lightValue = computed.getPropertyValue(`--color--${item}`);
    let darkValue = computed.getPropertyValue(`--dark--${item}`);
    if (lightValue.length) {
      if (!darkValue.length) darkValue = lightValue;
      lightColors[`--color--${item}`] = lightValue;
      darkColors[`--color--${item}`] = darkValue;
    }
  });

  if (!Object.keys(lightColors).length) {
    console.warn("No variables found matching tr-color-vars attribute value");
    return;
  }

  function setColors(colorObject, animate) {
    if (typeof gsap !== "undefined" && animate) {
      gsap.to(htmlElement, {
        ...colorObject,
        duration: colorModeDuration,
        ease: colorModeEase
      });
    } else {
      Object.keys(colorObject).forEach(function (key) {
        htmlElement.style.setProperty(key, colorObject[key]);
      });
    }
  }

  function goDark(dark, animate) {
    if (dark) {

CSS variables:

:root {
    --swatch--light: white;
    --swatch--transparent: rgba(255, 255, 255, 0);
    --swatch--brand: #8a2d59;
    --swatch--color: #1f1e3e;
    --swatch--dark: #201c1c;

    --color--background: var(--swatch--light);
    --color--text: var(--swatch--dark);
    --color--button-background: var(--swatch--brand);
    --color--button-text: var(--swatch--light);
    --color--toggle-bg: var(--swatch--light);
    --color--nav-menu-link: var(--swatch--light);
    --color--toggle-offset: 0rem;
    --color--background-50: rgba(255, 255, 255, .5);

    --dark--background: var(--swatch--dark);
    --dark--text: var(--swatch--light);
    --dark--button-background: var(--swatch--brand);
    --dark--button-text: var(--swatch--light);
    --dark--toggle-bg: var(--swatch--brand);
    --dark--nav-menu-link: var(--swatch--light);
    --dark--toggle-offset: 2rem;
    --dark--background-50: rgba(53, 50, 51, .5);
}

JavaScript not finding css-variables – darkmode toggle in a WordPress and webflow website

I have an issue with my WordPress website and some custom JavaScript I want to use. The code gets loaded into the site with this script tag on line 16 in the head-section:

<script tr-color-vars="text,background,button-background,button-text,background-50,nav-menu-link,toggle-bg,toggle-offset"
duration="0.5" ease="power1.out"
src="https://cdn.jsdelivr.net/gh/timothydesign/[email protected]/dark-mode-toggle.js">

‘tr-color-vars’ lists the variables I’d like to change between light and dark-mode. ‘src=’ calls the cdn-hosted code.

In my webflow website, where I converted the theme from, the toggle works fine.

On the WordPress site, the code from the script returns the error-message:

No variables found matching tr-color-vars attribute value

Yet the variables are there.

Why does the js-code not find the variables?

live webflow site (working example)

link of wordpress site (toggle issue)

I got this code and the how-to from timothy ricks on YouTube: https://www.youtube.com/watch?v=grA47dBXzPg

JavaScript code:

/**
 * Dark Mode Toggle 1.0.2
 * Copyright 2023 Timothy Ricks
 * Released under the MIT License
 * Released on: November 28, 2023
 */

function colorModeToggle() {
  function attr(defaultVal, attrVal) {
    const defaultValType = typeof defaultVal;
    if (typeof attrVal !== "string" || attrVal.trim() === "") return defaultVal;
    if (attrVal === "true" && defaultValType === "boolean") return true;
    if (attrVal === "false" && defaultValType === "boolean") return false;
    if (isNaN(attrVal) && defaultValType === "string") return attrVal;
    if (!isNaN(attrVal) && defaultValType === "number") return +attrVal;
    return defaultVal;
  }

  const htmlElement = document.documentElement;
  const computed = getComputedStyle(htmlElement);
  let toggleEl;
  let togglePressed = "false";

  const scriptTag = document.querySelector("[tr-color-vars]");
  if (!scriptTag) {
    console.warn("Script tag with tr-color-vars attribute not found");
    return;
  }

  let colorModeDuration = attr(0.5, scriptTag.getAttribute("duration"));
  let colorModeEase = attr("power1.out", scriptTag.getAttribute("ease"));

  const cssVariables = scriptTag.getAttribute("tr-color-vars");
  if (!cssVariables.length) {
    console.warn("Value of tr-color-vars attribute not found");
    return;
  }

  let lightColors = {};
  let darkColors = {};
  cssVariables.split(",").forEach(function (item) {
    let lightValue = computed.getPropertyValue(`--color--${item}`);
    let darkValue = computed.getPropertyValue(`--dark--${item}`);
    if (lightValue.length) {
      if (!darkValue.length) darkValue = lightValue;
      lightColors[`--color--${item}`] = lightValue;
      darkColors[`--color--${item}`] = darkValue;
    }
  });

  if (!Object.keys(lightColors).length) {
    console.warn("No variables found matching tr-color-vars attribute value");
    return;
  }

  function setColors(colorObject, animate) {
    if (typeof gsap !== "undefined" && animate) {
      gsap.to(htmlElement, {
        ...colorObject,
        duration: colorModeDuration,
        ease: colorModeEase
      });
    } else {
      Object.keys(colorObject).forEach(function (key) {
        htmlElement.style.setProperty(key, colorObject[key]);
      });
    }
  }

  function goDark(dark, animate) {
    if (dark) {

CSS variables:

:root {
    --swatch--light: white;
    --swatch--transparent: rgba(255, 255, 255, 0);
    --swatch--brand: #8a2d59;
    --swatch--color: #1f1e3e;
    --swatch--dark: #201c1c;

    --color--background: var(--swatch--light);
    --color--text: var(--swatch--dark);
    --color--button-background: var(--swatch--brand);
    --color--button-text: var(--swatch--light);
    --color--toggle-bg: var(--swatch--light);
    --color--nav-menu-link: var(--swatch--light);
    --color--toggle-offset: 0rem;
    --color--background-50: rgba(255, 255, 255, .5);

    --dark--background: var(--swatch--dark);
    --dark--text: var(--swatch--light);
    --dark--button-background: var(--swatch--brand);
    --dark--button-text: var(--swatch--light);
    --dark--toggle-bg: var(--swatch--brand);
    --dark--nav-menu-link: var(--swatch--light);
    --dark--toggle-offset: 2rem;
    --dark--background-50: rgba(53, 50, 51, .5);
}

In JavaScript, how do I check if there are objects with the same value in an array? (a little different)

How do I check if there are objects with the same value “name” in an array?

Input:

[
    {
        "name": "blabla",
        "value": "537,52"
    },
    {
        "name": "exactly",
        "value": "550,1"
    },
    {
        "name": "notthat",
        "value": "120,7"
    },
    {
        "name": "blabla",
        "value": "570,33"
    }
]

Output:

[
    {
        "name": "exactly",
        "value": "550,1"
    },
    {
        "name": "notthat",
        "value": "120,7"
    },
    {
        "name": "blabla",
        "value": "570,33"
    }
]

As in the example, i want the larger value to stay and the smaller value to go.

I searched but couldn’t find it

vulnerability fix npm react js spring boot heeeelpp

PLEASEE HELP
nth-check <2.0.1
Severity: high
Inefficient Regular Expression Complexity in nth-check – https://github.com/advisories/GHSA-rp65-9cf3-cjxr
fix available via npm audit fix --force
Will install [email protected], which is a breaking change
node_modules/svgo/node_modules/nth-check
css-select <=3.1.0
Depends on vulnerable versions of nth-check
node_modules/svgo/node_modules/css-select
svgo 1.0.0 – 1.3.2
Depends on vulnerable versions of css-select
node_modules/svgo
@svgr/plugin-svgo <=5.5.0
Depends on vulnerable versions of svgo
node_modules/@svgr/plugin-svgo
@svgr/webpack 4.0.0 – 5.5.0
Depends on vulnerable versions of @svgr/plugin-svgo
node_modules/@svgr/webpack
react-scripts >=2.1.4
Depends on vulnerable versions of @svgr/webpack
Depends on vulnerable versions of resolve-url-loader
node_modules/react-scripts

Severity: moderate
PostCSS line return parsing error – https://github.com/advisories/GHSA-7fh5-64p2-3v2j
fix available via npm audit fix --force
Will install [email protected], which is a breaking change
node_modules/resolve-url-loader/node_modules/postcss
resolve-url-loader 0.0.1-experiment-postcss || 3.0.0-alpha.1 – 4.0.0
Depends on vulnerable versions of postcss
node_modules/resolve-url-loader

8 vulnerabilities (2 moderate, 6 high)
this is package json “@date-io/date-fns”: “^3.0.0”,
this is the package json “dependencies”: {
“@date-io/date-fns”: “^3.0.0”,
“@emotion/react”: “^11.11.4”,
“@emotion/styled”: “^11.11.5”,
“@mui/icons-material”: “^5.15.5”,
“@mui/lab”: “^5.0.0-alpha.106”,
“@mui/material”: “^5.16.1”,
“@mui/x-date-pickers”: “^5.0.20”,
“@reduxjs/toolkit”: “^1.8.3”,
“@tabler/icons”: “^1.84.0”,
“@testing-library/jest-dom”: “^5.16.5”,
“@testing-library/react”: “^13.3.0”,
“@testing-library/user-event”: “^13.5.0”,
“ajv”: “^8.17.1”,
“apexcharts”: “^3.45.1”,
“axios”: “^1.7.2”,
“browser-image-compression”: “^2.0.2”,
“chance”: “^1.1.9”,
“chart.js”: “^4.4.1”,
“cors”: “^2.8.5”,
“date-fns”: “^2.22.1”,
“express”: “^4.19.2”,
“html2canvas”: “^1.4.1”,
“jspdf”: “^2.5.1”,
“jspdf-autotable”: “^3.8.2”,
“lodash”: “^4.17.21”,
“moment”: “^2.30.1”,
“prop-types”: “^15.7.2”,
“react”: “^18.2.0”,
“react-apexcharts”: “^1.4.1”,
“react-chartjs-2”: “^5.2.0”,
“react-dom”: “^18.2.0”,
“react-dropzone”: “^14.2.3”,
“react-helmet”: “^6.1.0”,
“react-icons”: “^5.0.1”,
“react-router”: “^6.3.0”,
“react-router-dom”: “^6.23.1”,
“react-signature-canvas”: “^1.0.6”,
“react-spring”: “^9.2.4”,
“react-transition-group”: “^4.4.5”,
“recharts”: “^2.10.4”,
“socket.io”: “^4.7.5”,
“socket.io-client”: “^4.7.5”,
“stylis-plugin-rtl”: “^2.0.2”,
“web-vitals”: “^2.1.4”,
“yup”: “^0.32.11”,
“css-select”: “^2.1.0”,
“svgo”: “^2.8.0”,
“@svgr/plugin-svgo”: “^6.5.1”,
“@svgr/webpack”: “^6.5.1”,
“postcss”: “^8.4.31”,
“resolve-url-loader”: “^4.0.0”
},
“devDependencies”: {
“@babel/plugin-proposal-private-property-in-object”: “^7.21.11”,
“eslint”: “^9.7.0”,
“eslint-config-prettier”: “^9.1.0”,
“eslint-config-react-app”: “^7.0.1”,
“eslint-plugin-prettier”: “^5.1.3”,
“eslint-plugin-react”: “^7.34.3”,
“eslint-plugin-react-hooks”: “^4.6.2”,
“prettier”: “^2.8.8”,
“react-scripts”: “^5.0.0”,
“webpack”: “^5.68.0”,
“webpack-cli”: “^5.1.4”
},
“scripts”: {
“start”: “react-scripts start”,
“build”: “react-scripts build”,
“test”: “react-scripts test”,
“eject”: “react-scripts eject”
},

i tried npm audit i tried a solution that i picked from stackoverflow but unfortunately nothing work

Positioning an input button and overriding SVG

No matter what I try to do, my Bezier Curve seems to push my button to the bottom of my screen. I’ve tried to use CSS and even the Javascript setAttribute to fix this problem, but nothing seems to work. How do I display my XHTML button so that it will be above the SVG Bezier curve? Can you assist me? Here is my HTML code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
     <title>SVG_Bezier_Curve</title>
      <link rel="stylesheet" type="text/css" href="http://localhost:8080/exist/rest/db/apps/HTML_Student/SVG_Bezier_Curve.css"/>
      <script language="javascript" src="http://localhost:8080/exist/rest/db/apps/HTML_Student/SVG_Bezier_Curve_2.js">
      
      </script>
</head>
<body onload = "Setup()">
     <input type="button" id="Bezier_Curve_Button" onclick="Setup2()" value="Click Me!" position = "absolute" top = "100px"/>
     <svg xmlns="http://www.w3.org/2000/svg" id="My_SVG" position = "absolute" top = "200px" height="500px" width="600px">
     <path id="Bezier_Curve_1"/>
     <path id="Bezier_Curve_2"/>
     </svg>
</body>

Here is my Javascript code:

    function Setup() {
    var Bezier_Curve_Identification;
    var Attribute_Name;
    var Attribute_Name_2;
    var Coordinate;
    var My_Properties;
    var Button_Identification;
    
    
    
    Attribute_Name = "d";
    Attribute_Name_2 = "style";
    My_Properties = "stroke: blue; stroke-width: 3; fill: none;";
    Coordinate = "M 375 200 A 50 50 0 0 1 475 200";
    Button_Identification = document.getElementById('Bezier_Curve_Button');
    Button_Identification.setAttribute = ("style", "top: 100px; height: 200px;");
    Bezier_Curve_Identification = document.getElementById('Bezier_Curve_1');
    Bezier_Curve_Identification.setAttribute(Attribute_Name, Coordinate);
    Bezier_Curve_Identification.setAttribute(Attribute_Name_2, My_Properties);
    
    
  
}

function Setup2() {
    
    var SVG_Data;
    var Retrieved_Data;
    var Bezier_Curve_1;
    var Bezier_Curve_2;
    var Counter;
    var Coordinate_Attribute;
    var Coordinate;
    var Style_Attribute;
    var Style_Details;
    var Bezier_Curve_Identification;
    
    SVG_Data = new XMLHttpRequest();
          SVG_Data.open("GET","http://localhost:8080/exist/rest/db/apps/HTML_Student/SVG_Bezier_Curve.xq", true);
          SVG_Data.onreadystatechange = function () {
              if (SVG_Data.readyState == 4) {
              Retrieved_Data = SVG_Data.responseText;
              Retrieved_Data = Retrieved_Data.split("/");
              Counter = 0;
              Bezier_Curve_1 = Retrieved_Data[Counter];
              Counter = Counter + 1;
              Bezier_Curve_2 = Retrieved_Data[Counter];}
              Bezier_Curve_1 = Bezier_Curve_1.split("*");
              Counter = 0;
              Coordinate_Attribute = Bezier_Curve_1[Counter];
              Counter = Counter + 1;
              Coordinate = Bezier_Curve_1[Counter];
              Counter = Counter + 1;
              Style_Attribute = Bezier_Curve_1[Counter];
              Counter = Counter + 1;
              Style_Details = Bezier_Curve_1[Counter];
              Bezier_Curve_Identification = document.getElementById('Bezier_Curve_1');
              Bezier_Curve_Identification.setAttribute(Coordinate_Attribute, Coordinate);
              Bezier_Curve_Identification.setAttribute(Style_Attribute, Style_Details);
              Bezier_Curve_2 = Bezier_Curve_2.split("*");
              Counter = 0;
              Coordinate_Attribute = Bezier_Curve_2[Counter];
              Counter = Counter + 1;
              Coordinate = Bezier_Curve_2[Counter];
              Counter = Counter + 1;
              Style_Attribute = Bezier_Curve_2[Counter];
              Counter = Counter + 1;
              Style_Details = Bezier_Curve_2[Counter];
              Bezier_Curve_Identification = document.getElementById('Bezier_Curve_2');
              Bezier_Curve_Identification.setAttribute(Coordinate_Attribute, Coordinate);
              Bezier_Curve_Identification.setAttribute(Style_Attribute, Style_Details);
              
              };

SVG_Data.send();}

And here is my CSS code:

 #Bezier_Curve_Button {
position: absolute;
top: 100px;
left: 50px;
height: 100px;
width: 150px;}

node.js v18 using babel – how to import module with extension and how to run from build folder (commonJS) while type:module is in package.json

I am using Node.JS v18.20.4 with Babel.
Here is my babel.config.json

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": 18
        },
        "debug": true,
        "useBuiltIns": "usage",
        "corejs": "3.37.1"
      }
    ]
  ]
}

Here is my package.json

"main": "src/app.js",
"type": "module",
"scripts": {
  "test": "echo "Error: no test specified" && exit 1",
  "start": "npm run build && node build/app.js",
  "build": "eslint src && babel src -d build --source-maps",
  "dev": "nodemon src/app.js"
},
"dependencies": {
    "core-js": "^3.37.1",
    "express": "^4.19.2"
  },
  "devDependencies": {
    "@babel/cli": "^7.24.8",
    "@babel/core": "^7.24.9",
    "@babel/preset-env": "^7.24.8",
    "@eslint/js": "^9.7.0",
    "eslint": "^9.7.0",
    "globals": "^15.8.0",
    "nodemon": "^3.1.4",
    "prettier": "^3.3.3"
  }

Here is npm start output.

[vagrant@linuxbox api]$ npm start

> [email protected] start
> npm run build && node build/app.js


> [email protected] build
> eslint src && babel src -d build --source-maps

@babel/preset-env: `DEBUG` option

Using targets:
{
  "node": "18"
}

Using modules transform: auto

Using plugins:
  transform-unicode-sets-regex { node < 20 }
  syntax-class-static-block
  syntax-private-property-in-object
  syntax-class-properties
  syntax-numeric-separator
  syntax-nullish-coalescing-operator
  syntax-optional-chaining
  syntax-json-strings
  syntax-optional-catch-binding
  syntax-async-generators
  syntax-object-rest-spread
  proposal-export-namespace-from { }
  transform-modules-commonjs
  proposal-dynamic-import
  syntax-top-level-await
  syntax-import-meta
corejs3: `DEBUG` option

Using targets: {
  "node": "18"
}

Using polyfills with `usage-global` method:

[/home/vagrant/xxxx/api/src/app.js]
Based on your code and targets, the corejs3 polyfill did not add any polyfill.

[/home/vagrant/xxxx/api/src/routes.js]
Based on your code and targets, the corejs3 polyfill did not add any polyfill.
Successfully compiled 2 files with Babel (1063ms).
file:///home/vagrant/xxxx/api/build/app.js:3
var _express = _interopRequireDefault(require("express"));
               ^

ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/home/vagrant/xxxx/api/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///home/vagrant/xxxx/api/build/app.js:3:16
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:337:24)
    at async loadESM (node:internal/process/esm_loader:34:7)
    at async handleMainPromise (node:internal/modules/run_main:106:12)

Node.js v18.20.4

and using nodemon

vagrant@linuxbox api]$ npm run dev

> [email protected] dev
> nodemon src/app.js

[nodemon] 3.1.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,cjs,json
[nodemon] starting `node src/app.js`
node:internal/errors:496
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/vagrant/xxxx/api/src/routes' imported from /home/vagrant/xxxx/api/src/app.js
    at new NodeError (node:internal/errors:405:5)
    at finalizeResolution (node:internal/modules/esm/resolve:327:11)
    at moduleResolve (node:internal/modules/esm/resolve:980:10)
    at defaultResolve (node:internal/modules/esm/resolve:1206:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:404:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:373:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:250:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:39)
    at link (node:internal/modules/esm/module_job:75:36) {
  url: 'file:///home/vagrant/xxxx/api/src/routes',
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v18.20.4
[nodemon] app crashed - waiting for file changes before starting...

Here is my app.js file look like

import express from 'express';
import routes from './routes';
// Creating express object
const app = express();

If I add .js explicitly like route.js on this line import routes from './routes.js';

Then my nodemon src/app.js command using npm run dev works fine. but I don’t want to use .js extension, Am I missing any configuration anywhere so it is not required?

If I add .js as above or not, npm start (npm run build && node build/app.js) still fails.
But if I change it to npm run build && node src/app.js and add .js explicitly, it also works.

  1. How can I eliminate .js when importing my modules?
  2. How can I run the npm run build && node build/app.js from the build folder which I believe babel has converted it to commonjs but because package.json has "type": "module” in it, it is throwing an error. If I remove that it throws an error that either I need to have mjs extension or "type": "module" in package.json.

This file is being treated as an ES module because it has a ‘.js’ file
extension and ‘/home/vagrant/xxxx/api/package.json’ contains “type”:
“module”. To treat it as a CommonJS script, rename it to use the
‘.cjs’ file extension.

It has become a catch-22 for me. 🙂

Any help would be appreciated.

Performance disadvantages of splitting every component into separate chunks in Nuxt?

So I’m working with Nuxt 2.15 (Vue 2.6). Usually if we have a component that is rendered using v-if (so it is not always needed) we import it like this:

  components: {
    SideCategory: () => import(/* webpackChunkName: "SideCategory" */
      '~/components/SideCategory.vue')
  },

And in the final build we get a separate JS chunk for this component. And we get it only when it is needed. So it is all fine.

But my question is – is there any potential drawback of importing every component like this?
I saw couple of times in the project I’m working on that components that are always rendered (without v-if) are being lazy imported. And I wonder if maybe it can hurt our performance?

Wouldn’t it be better to keep components that are always visible imported normally and let Nuxt/Webpack do its work? Meaning:

import Description from '~/components/Description.vue';
// ...
components: { Description }

Does creating a bunch of small chunks hurt the performance and core web vitals?
I guess it could make it slightly worse, but the difference for a single component would be to small to measure it so I can not validate it easily.

What do you think?

What’s the difference between component as prop or rendered component as prop (see examples below)

Let’s say I have a conponent name Child:

const Child =(props) => <div {...props}/>

and a parent component Parent, getting this component as prop named ComponentProp. What is the difference between passing the component and passing a rendered component?

Option1: passing component

const Parent = ({ComponentProp})=><div><ComponentProp/><div>

Usage:

<Parent ComponentProp={Component} />

Options: passing rendered component

const Parent = ({ComponentProp})=><div>{ComponentProp}<div>

Usage:

<Parent ComponentProp={<Component/>} />

Also, how it relates to child prop in react and server/client component in nextjs?

Find the average per inex in a matrix

I’m looking to get the average of each index in a matrix row in JS

[1, 2, 3]
[4, 5, 6]
[7, 8, 9]

Then returning a list with the average of each row index : [4, 5, 6]

Would I create a loop, save each index to a list, add them up, and divide them, then form new list with averages?
I feel like there is probably a simpler way.

Amadeus API: Error code 38189, ‘title’: ‘Internal error’, ‘detail’: ‘An internal error occurred, please contact your administrator status 500

I’m using Amadeus API and everything works fine when searching for flights, however, when I try to fetch ‘flight-offers/pricing’ and ‘booking/flight-orders (following amadeus documenatation) it’s giving the error:

"code": 38189,
"title": "Internal error",
"detail": "An internal error occurred, please contact your administrator",
"status": 500

I try to follow amadeusfordevelopers youtube channel simulating requests on postman and I receveid the same error Build a flight booking engine with Amadeus Self-Service APIs
I saw the other question about it amadeus api error 500, but I’m already using ‘Content-Type is “application/json”‘ and I’m using React/TS.

How to compare two tsx elements in react + tsx

i want to compare two react tsx elements. i am still new to react and tsx. but i am unale to do so even after copying and pasting the exact elements to compare. Can you tell me why and how to fix it?

Here is where i want to compare

function placeTile(index: number) {
    if (
      tiles[index] ===                  //Compare here
      (
        <div className="filler" id=".">
          .
        </div>
      )
    ) {
      let updateTile = tiles.slice();
      updateTile[index] = (
        <div className="filled" id={move}>
          {move}
        </div>
      );
      console.log("Filled a spot");
      setTiles(updateTile);
    } else {
      console.log("This is filled spot " + index);
    }
  }

The ’tiles’ is an array of the very same tsx elements declared as follows

let createTileSetup = Array(9).fill(
    <div className="filler" id=".">
      .
    </div>
  );

const [tiles, setTiles] = useState(createTileSetup);

If there is another way please tell me. their ids are different but i dont know how to compare those either. any help is appreciated

Chromium browsers: Select Option menu immediately closes after opening when scrolling

I’m encountering an issue with select elements in Chromium-based browsers. Here’s the specific problem:

  1. I scroll to the bottom of the page using a mouse with momentum scrolling.
  2. The page reaches the end, but the mouse continues to register scroll events due to momentum.
  3. When I click on a select element, the dropdown menu opens briefly but immediately closes.

This appears to happen because the browser is still processing the momentum scroll events, which interfere with the select element’s open state.

How can I prevent this behavior and keep the select dropdown open, even when clicked immediately after scrolling to the bottom of the page?

Firefox doensn’t seem to have this problem.

Multiple adding to cart in JavaScript doesn’t work

when I add products to the shopping cart at some point it stops updating the table, it is refreshed when I click the previous product and the product I want to add.

Live site: https://frontend-mentor-git-main-kkajets-projects.vercel.app/fm-product-list-with-cart/index.html
Repository: https://github.com/KKajet/frontend-mentor/tree/main/fm-product-list-with-cart

I would like it to update the number of products when you add as well as delete them.

const product = [
  {
    "image": {
      "thumbnail": "./assets/images/image-waffle-thumbnail.jpg",
      "mobile": "./assets/images/image-waffle-mobile.jpg",
      "tablet": "./assets/images/image-waffle-tablet.jpg",
      "desktop": "./assets/images/image-waffle-desktop.jpg"
    },
    "name": "Waffle with Berries",
    "category": "Waffle",
    "price": 6.5
  },
  {
    "image": {
      "thumbnail": "./assets/images/image-creme-brulee-thumbnail.jpg",
      "mobile": "./assets/images/image-creme-brulee-mobile.jpg",
      "tablet": "./assets/images/image-creme-brulee-tablet.jpg",
      "desktop": "./assets/images/image-creme-brulee-desktop.jpg"
    },
    "name": "Vanilla Bean Crème Brûlée",
    "category": "Crème Brûlée",
    "price": 7.0
  },
  {
    "image": {
      "thumbnail": "./assets/images/image-macaron-thumbnail.jpg",
      "mobile": "./assets/images/image-macaron-mobile.jpg",
      "tablet": "./assets/images/image-macaron-tablet.jpg",
      "desktop": "./assets/images/image-macaron-desktop.jpg"
    },
    "name": "Macaron Mix of Five",
    "category": "Macaron",
    "price": 8.0
  },
  {
    "image": {
      "thumbnail": "./assets/images/image-tiramisu-thumbnail.jpg",
      "mobile": "./assets/images/image-tiramisu-mobile.jpg",
      "tablet": "./assets/images/image-tiramisu-tablet.jpg",
      "desktop": "./assets/images/image-tiramisu-desktop.jpg"
    },
    "name": "Classic Tiramisu",
    "category": "Tiramisu",
    "price": 5.5
  },
  {
    "image": {
      "thumbnail": "./assets/images/image-baklava-thumbnail.jpg",
      "mobile": "./assets/images/image-baklava-mobile.jpg",
      "tablet": "./assets/images/image-baklava-tablet.jpg",
      "desktop": "./assets/images/image-baklava-desktop.jpg"
    },
    "name": "Pistachio Baklava",
    "category": "Baklava",
    "price": 4.0
  },
  {
    "image": {
      "thumbnail": "./assets/images/image-meringue-thumbnail.jpg",
      "mobile": "./assets/images/image-meringue-mobile.jpg",
      "tablet": "./assets/images/image-meringue-tablet.jpg",
      "desktop": "./assets/images/image-meringue-desktop.jpg"
    },
    "name": "Lemon Meringue Pie",
    "category": "Pie",
    "price": 5.0
  },
  {
    "image": {
      "thumbnail": "./assets/images/image-cake-thumbnail.jpg",
      "mobile": "./assets/images/image-cake-mobile.jpg",
      "tablet": "./assets/images/image-cake-tablet.jpg",
      "desktop": "./assets/images/image-cake-desktop.jpg"
    },
    "name": "Red Velvet Cake",
    "category": "Cake",
    "price": 4.5
  },
  {
    "image": {
      "thumbnail": "./assets/images/image-brownie-thumbnail.jpg",
      "mobile": "./assets/images/image-brownie-mobile.jpg",
      "tablet": "./assets/images/image-brownie-tablet.jpg",
      "desktop": "./assets/images/image-brownie-desktop.jpg"
    },
    "name": "Salted Caramel Brownie",
    "category": "Brownie",
    "price": 4.5
  },
  {
    "image": {
      "thumbnail": "./assets/images/image-panna-cotta-thumbnail.jpg",
      "mobile": "./assets/images/image-panna-cotta-mobile.jpg",
      "tablet": "./assets/images/image-panna-cotta-tablet.jpg",
      "desktop": "./assets/images/image-panna-cotta-desktop.jpg"
    },
    "name": "Vanilla Panna Cotta",
    "category": "Panna Cotta",
    "price": 6.5
  }
];

for (let i = 0; i < 9; i++) {
      
      const dessert = document.querySelector(".product-list");
      const prod = document.createElement("div");
      const img = document.createElement("img");
      const imgBtn = document.createElement("div");
      const itemInfo = document.createElement("div");
      const category = document.createElement("p");
      const name = document.createElement("p");
      const price = document.createElement("p");
      const btn = document.createElement("button");
      prod.classList.add("product");
      imgBtn.classList.add("imgBtn-container");
      dessert.append(prod);
      prod.append(imgBtn);
      imgBtn.append(img);
      imgBtn.append(btn);
      btn.classList.add(`cart-button${i}`, "text-preset-4-bold");
      btn.innerHTML = '<img src="./assets/images/icon-add-to-cart.svg" style="position: relative; top: 3px; " /> <span class="add-to-card">Add to Cart</span>';
      prod.append(itemInfo);
      img.src = product[i].image.desktop;
      img.classList.add("product-image");
      itemInfo.append(category);
      category.classList.add("text-preset-4", "category");
      category.innerText = product[i].category;
      itemInfo.append(name);
      name.classList.add("text-preset-3", "name");
      name.innerText = product[i].name;
      itemInfo.append(price);
      price.classList.add("text-preset-3", "price");
      price.innerText = `$${product[i].price.toFixed(2)}`;

      let quantity = [1, 1, 1, 1, 1, 1, 1, 1, 1];
      let buttonClick = document.querySelector(`.cart-button${i}`);
      buttonClick.addEventListener("click", function () {
        btn.classList.add("btn-clicked");
        btn.innerHTML = `<div class="flex-button decrement"><img src="./assets/images/icon-decrement-quantity.svg" style="position: relative; ";" /></div> <span class="add-to-card unit">${quantity[i]}</span> <div class="flex-button increment"><img src="./assets/images/icon-increment-quantity.svg" style="position:
          relative;  ";" /></div>`;
        let decreaseBtn = document.querySelector(".decrement");
        let increaseBtn = document.querySelector(".increment");
        let unitSpan = document.querySelector(`unit`);
        if (quantity[i] > 0) {
          decreaseBtn.addEventListener("click", function () {
            quantity[i]--;
            console.log(quantity);
            unitSpan.innerText = quantity[i];
          });
          increaseBtn.addEventListener("click", function () {
            quantity[i]++;
            console.log(quantity);
            unitSpan.innerText = quantity[i];
          });
        } else {
          quantity[i]++;
          console.log(quantity);
          btn.classList.remove("btn-clicked");
          btn.innerHTML = '<img src="./assets/images/icon-add-to-cart.svg" style="position: relative; top: 3px; " /> <span class="add-to-card">Add to Cart</span>';
        }
      });
}
@font-face {
  font-family: RedHatItalic;
  src: url(../assets/fonts/RedHatText-Italic-VariableFont_wght.ttf);
}
@font-face {
  font-family: RedHat;
  src: url(../assets/fonts/RedHatText-VariableFont_wght.ttf);
}
@font-face {
  font-family: RedHatBold;
  src: url(../assets/fonts/static/RedHatText-Bold.ttf);
}
@font-face {
  font-family: RedHatRegular;
  src: url(../assets/fonts/static/RedHatText-Regular.ttf);
}
@font-face {
  font-family: RedHatSemiBold;
  src: url(../assets/fonts/static/RedHatText-SemiBold.ttf);
}
* {
  margin: 0;
  padding: 0;
}

body {
  background-color: rgb(252, 248, 246);
  margin-block: 88px;
  margin-inline: 40px;
}

h1 {
  width: -webkit-min-content;
  width: -moz-min-content;
  width: min-content;
}

h2 {
  color: rgb(199, 59, 15);
}

.text-preset-1 {
  font-family: RedHatBold;
  font-size: 56px;
  line-height: 120%;
  letter-spacing: 0px;
}

.text-preset-2 {
  font-family: RedHatBold;
  font-size: 24px;
  line-height: 125%;
  letter-spacing: 0px;
}

.text-preset-3 {
  font-family: RedHatSemiBold;
  font-size: 16px;
  line-height: 150%;
  letter-spacing: 0px;
}

.text-preset-4 {
  font-family: RedHatRegular;
  font-size: 14px;
  line-height: 150%;
  letter-spacing: 0px;
}

.text-preset-4-bold {
  font-family: RedHatBold;
  font-size: 14px;
  line-height: 150%;
  letter-spacing: 0px;
}

.text-preset-5 {
  font-family: RedHatSemiBold;
  font-size: 14px;
  line-height: 150%;
  letter-spacing: 0px;
}

#main-page {
  max-width: 1306px;
  margin-left: auto;
  margin-right: auto;
}

.page {
  width: -webkit-max-content;
  width: -moz-max-content;
  width: max-content;
  height: 100%;
}

.product-list {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-wrap: wrap;
      flex-wrap: wrap;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
      -ms-flex-direction: row;
          flex-direction: row;
  color: rgb(38, 15, 8);
  float: left;
  margin-right: 32px;
  max-width: 800px;
}

.product {
  margin-top: 32px;
  margin-bottom: 24px;
}

.product:nth-of-type(2),
.product:nth-of-type(5),
.product:nth-of-type(8) {
  margin-inline: 24px;
}

.product-image {
  height: 240px;
  border-radius: 8px;
}

.category {
  color: rgb(135, 99, 90);
  margin-top: 16px;
}

.name {
  color: rgb(38, 15, 8);
}

.price {
  color: rgb(199, 59, 15);
}

.imgBtn-container button {
  width: 160px;
  height: 44px;
  border: 1px rgb(173, 138, 133) solid;
  border-radius: 160px;
  position: relative;
  bottom: 25px;
  left: 50px;
}

.btn-clicked {
  background-color: rgb(199, 59, 15);
  position: relative;
  bottom: 25px;
  left: 50px;
  border-radius: 160px;
  color: rgb(255, 255, 255);
}

.imgBtn-container button:hover {
  cursor: pointer;
}

.imgBtn-container .btn-clicked:hover {
  cursor: default;
}

.add-to-card {
  position: relative;
  bottom: 2px;
  left: 2px;
}

.imgBtn-container {
  width: 250px;
  height: 262px;
}

.flex-button {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  border: rgb(255, 255, 255) 1px solid;
  border-radius: 50px;
  width: 20px;
  height: 20px;
}

.decrement {
  position: relative;
  top: 10px;
  left: 15px;
}

.decrement:hover {
  background-color: rgb(255, 255, 255);
  cursor: pointer;
}

.increment {
  position: relative;
  bottom: 33px;
  left: 120px;
}

.increment:hover {
  background-color: rgb(255, 255, 255);
  cursor: pointer;
}

.unit {
  position: relative;
  bottom: 11px;
}

#cart {
  background-color: rgb(255, 255, 255);
  width: 384px;
  padding: 24px;
  float: right;
  border-radius: 12px;
  position: relative;
  bottom: 50px;
}

.your-cart {
  margin-bottom: 24px;
}

.info-add {
  color: rgb(135, 99, 90);
}

.empty-img {
  margin-bottom: 16px;
}

.empty-cart {
  text-align: center;
  padding-inline: 16px;
}

#footer {
  clear: both;
  position: relative;
  top: 30px;
}

@media only screen and (max-width: 1435px) {
  #cart {
    float: left;
    text-align: center;
    width: 762px;
    margin-top: 32px;
  }
  #main-page {
    max-width: 830px;
  }
  .product:nth-of-type(2),
  .product:nth-of-type(5),
  .product:nth-of-type(8) {
    margin-inline: 24px;
  }
}
@media only screen and (max-width: 940px) {
  #cart {
    width: 500px;
  }
  .product:nth-of-type(1),
  .product:nth-of-type(3),
  .product:nth-of-type(5),
  .product:nth-of-type(7),
  .product:nth-of-type(9) {
    margin-right: 24px;
    margin-left: 0;
  }
  .product:nth-of-type(8),
  .product:nth-of-type(2) {
    margin-left: 0;
    margin-right: 0;
  }
  #main-page {
    max-width: 556px;
  }
}
@media only screen and (max-width: 656px) {
  .product:nth-of-type(1) {
    margin: 0;
  }
  #main-page {
    max-width: 274px;
  }
  #cart {
    width: 200px;
  }
  .product-list {
    margin: 0;
  }
  body {
    background-color: rgb(252, 248, 246);
    margin-inline: 24px;
  }
}/*# sourceMappingURL=style.css.map */
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <link rel="icon" type="image/png" sizes="32x32" href="./assets/images/favicon-32x32.png" />
    <link rel="stylesheet" href="css/style.css" />

    <title>Frontend Mentor | Product list with cart</title>
  </head>
  <body>
    <main id="main-page">
      <h1 class="text-preset-1">Desserts</h1>
      <div class="product-list"></div>

      <div id="cart">
        <h2 class="text-preset-2 your-cart">Your Cart <span>(..)</span></h2>
        <div class="empty-cart">
          <img src="assets/images/illustration-empty-cart.svg" alt="empty card" class="empty-img" />
          <p class="info-add text-preset-4-bold">Your added items will appear here</p>
        </div>
      </div>
    </main>

    <!-- <footer id="footer">
      <div class="attribution">Challenge by <a href="https://www.frontendmentor.io?ref=challenge">Frontend Mentor</a>. Coded by <a href="#">Kajetan Ślęga</a>.</div>
    </footer> -->

    <script src="script/app.js"></script>
  </body>
</html>

How to assign a leaflet layer to a group, when that layer is created by an extension of leaflet

This R code creates a leaflet map with two base layers. The user can toggle between the two layers.

leaflet() |>
  addTiles(group = "group 1") |>
  addProviderTiles(provider = providers$CartoDB, group = "group 2") |>
  addLayersControl(baseGroups = c("group 1", "group 2"),
                   options = layersControlOptions(collapsed = F))

I want to create a map with two baselayers, but where one layer is created by a leaflet extension, not addProviderTiles().

This code successfully adds a layer to a leaflet map using the AllMaps plugin.

I’d like to assign the layer from AllMaps to a group, so that I can then use leaflet::addLayersControl() to toggle it on and off, as in the first example.

library(leaflet)
library(htmltools)
library(htmlwidgets)

allMapsPlugin <- htmlDependency(
  "@allmaps_leaflet", "1.0.0",
  src = c(href = 'https://cdn.jsdelivr.net/npm/@allmaps/[email protected]/dist/bundled'), 
  script = 'allmaps-leaflet-1.9.umd.min.js'
)

registerPlugin <- function(map, plugin) {
  map$dependencies <- c(map$dependencies, list(plugin))
  map
}

leaflet() |> 
  addTiles() |> 
  setView(lat = 51.054450, lng = 3.724924, zoom = 13) |> 
  registerPlugin(allMapsPlugin) |> 
  onRender("function(el, x) {
              const annotationUrl = 'https://annotations.allmaps.org/manifests/8f9faeba73d67031'
              const warpedMapLayer = new L.WarpedMapLayer(annotationUrl)
                    .addTo(this)
            }")

image showing the result of the leaflet extension

How can I assign the layer from the AllMaps plugin to a group?