How to override maxSize/priority for chunk named in dynamic import

I have a chunk I’m naming in a dynamic import as follows:

const FileAttachments = React.lazy(() => import(
    /* webpackPrefetch: true */
    /* webpackMode: "lazy" */
    /* webpackChunkName: "file-icons" */
    "Widgets/FileAttachments"));

This is a large chunk and it’s fine it if takes awhile to load (it’s rarely used and has a perfectly sensible fallback) and similarly for social-icons. How do I specify the priority and override the default maxsize I’ve set in webpack config. I tried adding this

        cacheGroups: {
            'file-icons': {
                maxSize: Infinity,
                priority: -100,
            },
            'social-icons': {
                maxSize: Infinity,
                priority: -70,
            },
         }

But that actually caused me to no longer have a chunk with the name file-icons. Maybe that’s expected because it was merged with another chunk but I don’t really understand if I’m doing this right. Or do I have to use a regexp to specify a cacheGroup if I want to override the default options for a chunk (I was hoping to let webpack do it’s think and split the chunks where it made sense while also lowering the priority and increasing the size maximum).

It’s possible that this question doesn’t even really make sense because, I admit, I don’t have a good grip on how the cacheGroups and chunk names work and when I should name them etc.. etc..

How to center a text in mui snackbar

I’m trying to center a text in a muisnackbar but unfortunately I can’t do it.
Here is the code

I am taker of any proposal

import Stack from "@mui/material/Stack";
import Button from "@mui/material/Button";
import Snackbar from "@mui/material/Snackbar";
import MuiAlert, { AlertProps } from "@mui/material/Alert";

const Alert = React.forwardRef<HTMLDivElement, AlertProps>(function Alert(
  props,
  ref
) {
  return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
});

export default function CustomizedSnackbars() {
  const [open, setOpen] = React.useState(false);

  const handleClick = () => {
    setOpen(true);
  };

  const handleClose = (
    event?: React.SyntheticEvent | Event,
    reason?: string
  ) => {
    if (reason === "clickaway") {
      return;
    }

    setOpen(false);
  };

  return (
    <Stack spacing={2} sx={{ width: "100%" }}>
      <Button variant="outlined" onClick={handleClick}>
        Open success snackbar
      </Button>
      <Snackbar open={open} autoHideDuration={6000} onClose={handleClose}>
        <Alert onClose={handleClose} severity="success" sx={{ width: "100%" }}>
          This is a success message!
        </Alert>
      </Snackbar>
    </Stack>
  );
}

I tested justifyContent, AlignItem , AlignContent but in vain
Thank you in advance

My program reads on of my properties as undefined

So I am trying to fix my starting page on my website but it just printing out my error
Cannot read properties of undefined (reading ‘username’) this is my error

I tried to fix my error by deleting it but it keept on printing out the error but with a different property so I think the problem is not that property but singleHighscore

const express = require("express");
const router = express.Router();
const db = require("../queries");

/* GET home page. */
router.get("/", async function (req, res, next) {
  const highscore = await db.getHighscore(1);
  const game = await db.getGame(1);
  const games = await db.getGames(10);
  const highscores = await db.getHighscores(10);
  const searchGames = await db.getSearch("C");
  res.render("index", {
    title: "Express",
    games: games,
    highscores: highscores,
    singleHighscore: highscore,
    singleGame: game,
    searchGames: searchGames,
  });
});

module.exports = router;

This top code is the one that affect the bottom code

<div>
  <p><%=singleHighscore.username%></p>
  <p><%=singleHighscore.game.name%></p>
  <p><%=singleHighscore.score%></p>
  <p><%=singleHighscore.active%></p>
</div>

socket.io console.log(userName) not showing in the command line

I’m creating a chat application using socket.io, so basically what I’m trying is to console.log the user who joined the chat, here I’m taking a prompt from the client and emitting to the server, but cannot find any log in my command line. And on top I’m getting this error ERR_NAME_NOT_RESOLVED.

ERR_NAME_NOT_RESOLVED img
Index Html:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>See-me</title>
        <script src="http://localhost:3000/socket.io/socket.io.js"></script>
        <script src="js/client.js"></script>
        <link rel="stylesheet" href="css/styles.css">
        <link rel = "icon" href ="logo/appIcon.ico" type = "image/x-icon">
</head>
<body>
   
</body>
</html>

Client Side Js:

    const socket = io('http//localhost:3000')

    const form = document.getElementById('send-container')
    const messageInput = document.getElementById('messageImp')
    const messageContainer = document.querySelector(".container")

const userName = prompt("Enter your Name to join");
socket.emit('new-user-joined', userName)

Server Side JS:

const io = require('socket.io')(3000)

const users = {};

io.on('connection', (socket) => {
    socket.on('new-user-joined', userName =>{
        console.log("New user", userName);
        users[socket.id] = userName;
        socket.broadcast.emit('user-joined', userName)
    });

    socket.on('send', message => {
        socket.broadcast.emit('receive', {message: message, userName: users[socket.id]})
    });
})

All I want is to console log the user who joined the chat.

How to calculate sum in th:each thymeleaf?

I have a list of persons that I need to display, and for each person there is an input for age.

I need to sum the ages when im writing; I mean if I have 5 persons when I’m on the 5th record, i need the total of previous 4 ages like this one : Calculate sum from number type input fields by javascript

this is my code :

  <tr th:each="person : ${persons}">
            <td th:text="${person.first_name}"></td>
            <td th:text="${person.last_name}"></td>
            <td th:text="${person.phone}"></td>
            <td><input id="age" class="form-control"
                        type="text" name="age" th:field="*{ages}">
            </td>
    </tr>

Total : <input type="text" name="total" id="total"/>

a given URL is the access location for the source files for the library

My task was to merge two videos together and play them one after another automatically.
This is the source code of my project
html code –

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>video js</title>
    <link rel="stylesheet" href="index.css">
</head>
<body>
    <video id="videoPlayer" width="500" height="350" controls style="background:black">
        <source class="current" src="MY_VIDEO.mp4" type="video/mp4" />
        <source src="video2.mp4" type="video/mp4" />
      </video>
    <script src="script.js"></script>
</body>
</html>

script code –


var video = document.getElementById('videoPlayer');

video.addEventListener('ended', function(event) {
  var currentVid = document.querySelector("#videoPlayer source.current");
  var nextVid = document.querySelector("#videoPlayer source.current + source") || document.querySelector("#videoPlayer source:first-child");
  
  currentVid.className = "";
  nextVid.className = "current";
  
  video.src = nextVid.src;
  video.play();
});

My next task says https://videojs.com/ is the URL to access the source files for the library.
I am not getting what does this means?
Any idea?
Thanks in advance 🙂

why does the keyword ‘this’ not work with a background-image in my code [duplicate]

i want to put a background image in a div and it works well with the classname but not with the keyword “this”. how is this possible and what are the solutions?

 $('#txtElement1').on('keypress', () =>{
                    if(event.code == "Enter"){
                        const invoerTextveld = $('#txtElement1').val();
                        $('ul').append('<div class="outputCheck"></div> <li class="liText">' + invoerTextveld + '</li>' + '<hr class="hr">');
                       
                        $('.outputCheck').on('click', () =>{
                            console.log(this)
                           $(this).css('background-image', 'url(images/Group4.png)');
                        })
                    } 
            })

Get path property from multi-dimentional array [duplicate]

struggling to figure this out. What is the cleanest code to extract all paths from a multi-dimentional array?

Below is my data.

const Pages = [
  {
    path: ['home'],
  },
  {
    path: [''],
    subpages: [
      {
        path: ['about', 'congleton'],
        subpages: [
          {
            path: [ 'about', 'congleton', 'opening' ]
          }
        ]
      }
    ]
  }
]

And this is the expected outcome:

[ ['home'], [''], ['about', 'congleton'], [ 'about', 'congleton', 'opening' ] ]

This is what I have right now, but this doesn’t work:

const getPath = function (page) {
  let paths = page.path;
  if (page.subpages) {
    const sub = page.subpages ? page.subpages.map((x) => getPath(x)) : [];
    paths = paths.concat(sub);
  }
  return paths;
};

const paths = Pages.map((x) => getPath(x));

console.log(paths);

ML5 can’t train XOR

// dataset
{ a: 0, b: 0, output: 'zero' },
{ a: 1, b: 0, output: 'one' },
{ a: 0, b: 1, output: 'one' },
{ a: 1, b: 1, output: 'zero' },

const options : {
  task: 'regression',
};

// outputs
// 0,0 => zero
// 1,0 => one
// 0,1 => one
// 1,1 => one

I’m not able to figure out what is going on, the learning process seems to be successfull.

Demo https://stackblitz.com/edit/react-ts-ut9iyb?file=App.tsx

(note: it doesn’t load at first due to the way I load ML5, you have to edit a file and save in order to get it to start.)

Stop parent event handler without editing all child event handlers

I have a parent element with several child elements, some of which have their own listeners and others don’t. The parent element has click handler that I want to run only if I click on the parent itself and not any of the child elements.

document.getElementById('parent').addEventListener('click', ()=> console.log('parent clicked'))

document.getElementById('child2').addEventListener('click', ()=> console.log('child2 clicked'))
#parent {
height: 300px;
width: 300px;
background-color: Lightgreen;
wrap: true;
display: flex;
flex-direction:column;
gap: 20px;
padding: 50px 50px;
}

#parent * {
height: 100px;
width: 100px;
background-color: white;
text-align: center;
display: grid;
place-items: center;
}
<div id="parent"> parent -Only log 'parent' when green background is clicked and nothing else-
  <div id="child1">child1 <br> -Nothing should happen when clicked-</div>
  <div id="child2">child2 <br> -Should only log -child 2 if clicked-</div>
</div>

I tried stopPropagation() but it works to stop handlers from firing when bubbling up, so I’d need to add it to all child event handlers, and I still can’t stop the parent from firing when clicking on objects without event listeners.

Is there a way to restrict the parent handler only when clicking on the element itself?

how can i prevent duplicated item when adding it in reactjs ( read the description pls )

I have 2 files named “task” and “search”
I’ve rendered the task component in search ( so when the search matches it renders items from task component)
this is my Search component

const getFilteredItems = (query, todos) => {
  if (!query) {
    return todos;
  }
  return todos.filter((todo) => todo.title.includes(query));
};
const Search = (props) => {
  const [query, setQuery] = useState("");
  const { todos, setTodos } = useContext(todosContext);
  const filteredItems = getFilteredItems(query, todos);

  return (
    <StyledDiv>
      <StyledInput
        type="search"
        marginTop="25px"
        onChange={(e) => setQuery(e.target.value)}
        placeholder="search..."
      />
      {filteredItems.map((todo) => (
        
        <Task />
      ))}
    </StyledDiv>
  );
};

export default Search;

and this is my Task component

 const { todos, setTodos } = useContext(todosContext);
  return (
    <div>
      {todos.map((todo) => (
        <div key={todo.id}>
          <ul>
            <li>{todo.title}</li>
            <li>{todo.description}</li>
          </ul>
          <Button
            backgroundColor={"#ff3838"}
            disabled={loading}
            onClick={() => deleteHandler(todo.id)}
          >
            Delete
          </Button>

          <Checkbox
            type={"checkbox"}
            placeholder={"completed"}
            onChange={(e) => processChange(e, todo.id)}
            checked={todo.completed}
            disabled={loading}
          />
        </div>
      ))}
    </div>
  );
};

export default Task;

but when I add items
it duplicates ( I’m pretty sure that’s because of those 2 map functions in each of these components and I could fix the problem by combining these 2 components into one
but is there any way to have 2 separated component and fix the issue ?
idk if that helps or not but this is the content of my todoContext file

import { createContext } from "react";

export const todosContext = createContext();