Link from react-router-dom element not working as expected inside useDraggable from dnd-kit-core. Colliding onClick listener (maybe)

Here is the situation:

I did a kanban board using dnd-kit and I put a there a link element from React Router that when is clicked loads the entire page instead updating the element.

Already checked the following aspects:

  • Routes properly configured on App.tsx file
  • BrowserRouter as parent element on main.tsx file
  • Link element working behaviour out of the draggable element from dnd-core works as expected, which tells me that this is maybe an onClick crash between draggable element and Link element.

The following sources were consulted but didn’t clarify anything to me:

  1. https://community.auth0.com/t/page-is-refreshing-every-time-a-new-route-is-clicked-react-spa/66597
    –> I’m using “to” prop instead href.
  2. https://dev.to/alexanie_/link-component-in-react-router-3e83 –> I checked that reloadDocument is not set up.

Also the Link element works fine when I comment the {…listeners} part of my code.

This are the relevant parts of my code, any help is appreciated, also if you need aditional parts of my code I will be updating this question:

Draggable.tsx file:

interface DraggableUserProps {
  user: User;
}

const DraggableUser: React.FC<DraggableUserProps> = ({ user }) => {
  const { attributes, listeners, setNodeRef, transform } = useDraggable({
    id: user.id,
  });

  const style = {
    transform: `translate3d(${transform?.x}px, ${transform?.y}px, 0)`,
    border: "1px solid gray",
    borderRadius: "5px",
    padding: "10px",
    margin: "5px",
    backgroundColor: "white",
  };

  return (
    <div>
      <div
        ref={setNodeRef}
        style={style}
        {...listeners}
        {...attributes}
        onMouseEnter={(e) => {
          e.currentTarget.style.backgroundColor = "#8296a2";
          e.currentTarget
            .querySelectorAll("svg")
            .forEach((el: any) => (el.style.color = "white"));
        }}
        onMouseLeave={(e) => {
          e.currentTarget.style.backgroundColor = "white";
          e.currentTarget.querySelectorAll("svg").forEach((el: any) => {
            if (el.parentElement.className != "user-info") {
              el.style.color = "green";
            } else {
              el.style.color = "#8296a2";
            }
          });
          e.currentTarget.style.color = "black";
        }}
      >
        {/* Link element that works as expected */}
        <Link className="more-info" key={`useris${user.id}`} to="/user-details">
            <InfoIcon style={{ color: "#8296a2" }} className="user-info" />
        </Link>
        <div
          // onClick={(e) => e.stopPropagation()} Commented because didn't work
          style={{ display: "flex", justifyContent: "space-between" }}
        >
          <Link
            className="more-info"
            key={`useris${user.id}`}
            to="/user-details"
          >
            <InfoIcon style={{ color: "#8296a2" }} className="user-info" />
          </Link>
          {user.name}{" "}
          <a
            href={`https://wa.me/${user.phone}?text=${user.message.replace(
              " ",
              "%20"
            )}`}
          >
            <WhatsApp
              style={{ color: "green" }}
              onMouseEnter={(e) =>
                (e.currentTarget.style.transform = "scale(1.5)")
              }
              onMouseLeave={(e) =>
                (e.currentTarget.style.transform = "scale(1)")
              }
            />
          </a>
        </div>
      </div>
    </div>
  );
};

export default DraggableUser;

App.tsx file:

import React from "react";
import "bootstrap/dist/css/bootstrap.css";
import { Routes, Route } from "react-router-dom";
// import Routes from "./Routes.tsx"; Ver como importar
import "./App.css";
import ResponsiveAppBar from "./components/General/ResponsiveAppBar";
import myRoutes from "./components/api/myroutes";
import ProtectedRoute from "./components/api/protectedRoute";
import UserDetails from "./components/parts/crm/UserDetails";

function App() {
  return (
    <>
      <ResponsiveAppBar myItems={myRoutes} />
      <Routes>
        {myRoutes
          // .filter((elmnt) => elmnt.path !== "/user-details/:id")
          .map((elmnt) =>
            elmnt.protected ? (
              <Route
                key={elmnt.path}
                path={elmnt.path}
                element={<ProtectedRoute element={elmnt.element} />}
              />
            ) : (
              <Route
                key={elmnt.path}
                path={elmnt.path}
                element={elmnt.element}
              />
            )
          )}
        {/* <Route path="/user-details" element={<UserDetails />} /> */}
      </Routes>
    </>
  );
}

export default App;

Main.tsx file:

import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.tsx";
import { BrowserRouter } from "react-router-dom";
import { AuthProvider } from './components/General/AuthProvider';

ReactDOM.createRoot(document.getElementById("root")!).render(
  <React.StrictMode>
    <AuthProvider>
      <BrowserRouter>
        <App />
      </BrowserRouter>
    </AuthProvider>
  </React.StrictMode>
);

I would like to know if there is a way in which listeners from React Router Link element and dnd-kit useDraggable wouldn’t collide.

onClick={(e) => e.stopPropagation()}

didn’t work.

Thanks in advance guys.

Variable becomes undefined when I link its class as a script

I am using javascript and have a map generation class called generate.js,which whenever I link as a script to any HTML file I get the error Uncaught (in promise) ReferenceError: scl is not defined. From what I can see scl is defined normally, this is especially a problem because I need generate.js for a crucial feature in my website, if you can find what is causing scl to become undefined or how to solve it, I would appreciate it.

Below is the code for generate.js, map_display.html from which the values are defined, and load.html which includes the feature I was talking about(a JSON loader)

let cols, rows;
let terrain = [];

let generating = false;

function setup() {
  createCanvas(width, height);
  background(200);
  noiseDetail(10,0.5);
  cols = width / scl;
  rows = height / scl;
  noiseSeed(seed);

  for (let x = 0; x < cols; x++) {
    terrain[x] = [];  
    for (let y = 0; y < rows; y++) {
      terrain[x][y] = 0;
    }
  }
}

function generateTerrain() {
  let yoff = 0;
  for (let y = 0; y < rows; y++) {
    let xoff = 0;
    for (let x = 0; x < cols; x++) {
      let noiseValue = noise(xoff / zoomFactor,yoff / zoomFactor);
      terrain[x][y] = noiseValue;
      xoff += noiseScale;
    }
    yoff += noiseScale;
  }
}

function draw() {
  if (generating) {
    generateTerrain();
    loadPixels();
    
    for (let y = 0; y < rows; y++) {
      for (let x = 0; x < cols; x++) {
        let val = terrain[x][y];
        let colorVal = getColor(val);
        
        fill(colorVal);
        noStroke();
        rect(x * scl, y * scl, scl, scl);
      }
    }
    noLoop();
    generating = false;
  }
}

function getColor(val) {
  let c1, c2;

  if (val < 0.35) {
    c1 = color(0, 0, 255); 
    c2 = color(0, 0, 180); 
    val = map(val, 0, 0.3, 0, 1);
  } else if (val < 0.45) {
    c1 = color(244, 164, 96); 
    c2 = color(255, 204, 153);
    val = map(val, 0.3, 0.4, 0, 1);
  } else if (val < 0.7) {
    c1 = color(34, 139, 34);
    c2 = color(0, 100, 0);
    val = map(val, 0.4, 0.7, 0, 1);
  } else {
    c1 = color(139, 69, 19); 
    c2 = color(205, 133, 63);
    val = map(val, 0.7, 1, 0, 1);
  }
  return lerpColor(c1, c2, val);
}

function generateMap() {
  let width = parseInt(document.getElementById('width').value);
  let height = parseInt(document.getElementById('height').value);
  let scl = parseInt(document.getElementById('scl').value);
  let noiseScale = parseFloat(document.getElementById('noiseScale').value);
  let zoomFactor = parseFloat(document.getElementById('zoomFactor').value);
  let seed = parseInt(document.getElementById('seed').value);
  if(!seed){
    seed = Math.floor(Math.random()*10000);
  }

  let url = `map_display?width=${width}&height=${height}&scl=${scl}&noiseScale=${noiseScale}&zoomFactor=${zoomFactor}&seed=${seed}`;

  window.location.href = url;
}
<!DOCTYPE html>
<html>
  <head>
    <title>Perlin Noise Terrain</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <h1>Fuming's Generator</h1>

    <nav class="navbar">
        <ul>
          <li><a href="/">Home</a></li>
          <li><a href="/map">Perlin Map Generator</a></li>
          <li><a href="/load">Load Downloaded Map</a></li>
          <li><a href="/about">About</a></li>
          <li><a href="/map">Map list</a></li>
        </ul>
    </nav>
     <script>
        const searchParams = new URLSearchParams(window.location.search);

        let width = parseInt(searchParams.get('width'));
        let height = parseInt(searchParams.get('height'));
        let scl = parseInt(searchParams.get('scl'));
        let noiseScale = parseFloat(searchParams.get('noiseScale'));
        let zoomFactor = parseFloat(searchParams.get('zoomFactor'));
        let seed = parseInt(searchParams.get('seed'));
    </script>
    <script src="/generate.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.min.js"></script>

    <script>
       generating = true;
    </script>

    <div class="content">
       <button onclick="saveSettings(width,height,scl,noiseScale,zoomFactor,seed)">Save Settings</button>
    </div>
    <script src="/save.js"></script>
  </body>
</html>
body{
    margin:0;
    padding:0;
}

h1{
    text-align:center;
    color:white;
    background-color:black;
    width:100%;
    padding:20px;
    box-sizing:border-box;
    margin:0;
    position:fixed;
    top:0;
    left:0;
    height:70px;
    z-index: 1000;
}

.content{
    margin-left: 220px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.content h2{
    text-align: center;
    font-size: 30px;
    margin-bottom: 20px;
    color: #333;
}

.navbar{
    width: 200px;
    height: calc(100vh-70px);
    background-color: lightgray;
    position: fixed;
    top: 70px;
    left: 0;
    bottom:0;
    padding: 0;
    margin: 0;
    overflow-y:auto;
    z-index: 999;
}
.navbar ul{
    list-style-type:none;
    background-color:lightgray;
    padding: 0px;
    margin: 0px;
}
.navbar a{
    display:block;
    padding:10px;
    width:100%;
    padding:10px;
    box-sizing:border-box;
    text-decoration:none;
}
.navbar a:hover{
    background-color:#b5b5b5;
}

.content {
    margin-left: 220px;
    padding: 20px;
    margin-top:60px;
  }
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Load Map Settings</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <h1>Load Map Settings</h1>

    <nav class="navbar">
        <ul>
            <li><a href="/">Home</a></li>
            <li><a href="/map">Perlin Map Generator</a></li>
            <li><a href="/load">Load Downloaded Map</a></li>
            <li><a href="/about">About</a></li>
        </ul>
    </nav>

    <div class="content">
        <input type="file" id="load-json" accept=".json">
        <p>Choose a JSON file with the saved map settings to load and generate the map.</p>
    </div>

    <script>
            document.getElementById('load-json').addEventListener('change', function(event) {
          const file = event.target.files[0];
          if (file) {
             const reader = new FileReader();
              reader.onload = function(e) {
                 const jsonData = JSON.parse(e.target.result);
                 width = jsonData.width;
                 height = jsonData.height;
                 scl = jsonData.scl;
                 noiseScale = jsonData.noiseScale;
                 zoomFactor = jsonData.zoomFactor;
                 seed = jsonData.seed;
                 console.log(width,height,scl,noiseScale,zoomFactor,seed);
          };
          reader.readAsText(file);
             }
        });

        generating = true;
        
    </script>
    <script src="generate.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
</body>
</html>

Component state reset and UI tree with different JSX syntax

I am referring to examples on this page and it is pertaining to React preserving state based on different conditions specific to the UI tree.

Specifically, is there any difference in the way React sees the below being rendered dynamically from a UI tree perspective?

  • Option 1:

    return (
      <div>
        {isPlayerA ? (
          <Counter person="Taylor" />
        ) : (
          <Counter person="Sarah" />
        )}
      </div>
    );
    
  • Option 2:

    return (
      <div>
        {isPlayerA && <Counter person="Taylor" />}
        {!isPlayerA && <Counter person="Sarah" />}
      </div>
    );
    

How to deactivate a previous event with getZr.on()

I’m using the following code to deactivate a previous event:

    chartUse.getZr().on('mouseout', params => {

        if (params.seriesIndex === 0) {

            chartUse.setOption({
                series: [
                    {},
                    {
                        axisLine: {
                            lineStyle: {
                                color: [[1, '#333']]
                            }
                        }
                    }
                ]
            })

        }

    });

But it doesn’t work. In other words, the code does not remove the color #f00 applied in the previous configuration.

When I move the mouse away from seriesIndex === 0 (line chart), I need the color to return to normal (#333), which is not happening.

Complete code:

  document.addEventListener("DOMContentLoaded", () => {

        const chartSystem = () => {

            return {
                "source": {
                    "bar": [
                        ["x", "y", "groups"],
                        ["Jan", 20, "group1"],
                        ["Feb", 36, "group1"],
                        ["Mar", 55, "group1"],
                        ["Apr", 24, "group2"],
                        ["May", 81, "group2"],
                        ["Jun", 61, "group2"]
                    ],
                    "gauge": [
                        ["name", "value", "groups"],
                        ["Pressure", 30, "group1"],
                        ["Temperature", 66, "group2"]
                    ]
                }
            }

        }

        const pullDataset = [];
        const pullData = [];

        const chartSend = () => {

            const { source } = chartSystem();

            pullDataset.push(...Object.values(source).slice(0, 1).map(item => ({
                source: item,
                sourceHeader: true
            })));

            pullData.push(...Object.values(source).slice(1).map(item => ({
                data: item.slice(1).map( ([name, value, groups]) => ({
                    name, 
                    value,
                    groupId: groups,
                    detail: {
                        backgroundColor: '#bcd090'
                    }
                }))
            })));

        }

        chartSend();

        const chartUse = echarts.init(document.getElementsByClassName('chart')[0]);

        function chartFrameSwitch0 () {

            const tooltip0 = {
                show: true
            };

            const grid0 = [
                {
                    width: '40%',
                    height: '35%',
                    left: '5%'
                }
            ];

            const xAxis0 = [
                {
                    type: 'category',
                    gridIndex: 0,
                    name: 'months',
                    nameTextStyle: {
                        color: '#000'
                    }
                }
            ];

            const yAxis0 = [
                {
                    type: 'value',
                    gridIndex: 0
                }
            ];

            const series0 = [
                {
                    type: 'line',
                    datasetIndex: 0,
                    encode: {
                        x: 0,
                        y: 1,
                        itemGroupId: 2
                    }
                },
                {
                    type: 'gauge',
                    center: ['75%', '50%'],
                    min: 0,
                    max: 100,
                    axisLine: {
                        lineStyle: {
                            width: 3,
                            color: [[1, '#333']]
                        }
                    },
                    data: pullData[0].data
                }
            ];

            const option = {
                dataset: [pullDataset[0]],
                tooltip: tooltip0,
                grid: grid0,
                xAxis: xAxis0,
                yAxis: yAxis0,
                series: series0
            };

            chartUse.setOption(option);

        }

        chartFrameSwitch0();
        
        // Adicionando evento de mousemove no gráfico
        chartUse.getZr().on("mousemove", params => {

            // (1) get pixel coordinates
            const pixelCoords = [params.offsetX, params.offsetY];
            
            // (2) seriesIndex apply coordinates
            const isOverAxisChart = chartUse.containPixel({ gridIndex: 0 }, pixelCoords);
            
            if (isOverAxisChart) {

                const usePixel = chartUse.convertFromPixel({ gridIndex: 0 }, pixelCoords);

                console.log(usePixel);

                chartUse.setOption({
                    series: [
                        {}, 
                        {
                            axisLine: {
                                lineStyle: {
                                    color: [[1, '#f00']]
                                }
                            },
                            detail: {
                                backgroundColor: '#bcd090',
                                formatter: value => value.toFixed(1)
                            },
                            data: [
                                {
                                    value: usePixel[0], 
                                    detail: {
                                        offsetCenter: ['-20%', '70%']
                                    }
                                }, 
                                {
                                    value: usePixel[1],
                                    detail: {
                                        offsetCenter: ['20%', '70%']
                                    }
                                }
                            ]
                        }
                    ]
                });

                chartUse.dispatchAction({
                    type: 'showTip',
                    seriesIndex: 1,
                    dataIndex: 1
                });

            }
        
        });

        chartUse.getZr().on('mouseout', params => {

            if (params.seriesIndex === 0) {

                chartUse.setOption({
                    series: [
                        {},
                        {
                            axisLine: {
                                lineStyle: {
                                    color: [[1, '#333']]
                                }
                            }
                        }
                    ]
                })

            }

        });
 
    });
<head>
    <script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/echarts.min.js'></script>
</head>

<div class='chart' style='width: 100%; height: 100vh;'></div>

I also tried using the globalout event, but to no avail:

    chartUse.getZr().on('globalout', params => {

        if (params.seriesIndex === 0) {

            chartUse.setOption({
                series: [
                    {},
                    {
                        axisLine: {
                            lineStyle: {
                                color: [[1, '#333']]
                            }
                        }
                    }
                ]
            })

        }

    });

Leaflet: Markers only visible after zooming, how to make them always visible?

I have installed Leaflet and created a map with several markers. The map works correctly, but the markers are only visible when I zoom in. I want the markers to always be visible regardless of the zoom level. How can I achieve this?
Here’s a snippet of my code:

<template>
  <section class="py-16">
    <h1 class="text-5xl font-medium capitalize text-tfc-550 my-4 text-center">
      Sedi
    </h1>
    <section>
      <div v-if="isClient" class="w-full h-140" id="map">
      </div>
      <div v-else class="text-center text-gray-500">
        Caricamento della mappa in corso...
      </div>
    </section>
  </section>
</template>

<script setup lang="ts">
import "leaflet/dist/leaflet.css"
import { ref, onMounted } from "vue"

const isClient = ref(false)

onMounted(async () => {
  isClient.value = true

  if (typeof window !== "undefined") {
    const L = (await import("leaflet")).default
    //@ts-ignore
    await import("leaflet.markercluster")
    
    const map = L.map("map")
    
    L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
      attribution: "&copy; OpenStreetMap contributors",
    }).addTo(map)

    const markers = L.markerClusterGroup()

    // Marker data
    const sedi = [
      { lat: 41.896852, lng: 12.481293, name: "Roma" },
      { lat: 45.532203, lng: 10.208898, name: "Brescia" },
      { lat: 45.483062, lng: 9.206098, name: "Milano" },
      { lat: 40.678369, lng: 14.765663, name: "Salerno" },
      { lat: 40.834449, lng: 14.229847, name: "Napoli" }
    ]

    sedi.forEach((sede) => {
      const marker = L.marker([sede.lat, sede.lng]).bindPopup(`<b>${sede.name}</b>`)
      markers.addLayer(marker) 
    })

    map.addLayer(markers)

    setTimeout(() => {
      const bounds = markers.getBounds()
      if (bounds.isValid()) {
        map.fitBounds(bounds)
      } else {
        console.error("Bounds non validi. Controlla i dati dei marker.")
      }
      map.invalidateSize()
      
    }, 100)
  }
})
</script>
<style scoped>

</style>

Here are my installed dependencies:

"dependencies": {
  "@nuxtjs/leaflet": "^1.2.6",
  "@pinia/nuxt": "^0.7.0",
  "@vueuse/core": "^10.7.2",
  "apexcharts": "^3.45.2",
  "glightbox": "^3.3.0",
  "gumshoejs": "^5.1.2",
  "leaflet.markercluster": "^1.5.3",
  "lucide-vue-next": "^0.469.0",
  "nuxt": "^3.14.1592",
  "pinia": "^2.2.6",
  "preline": "^2.0.3",
  "swiper": "^11.0.6",
  "vue": "^3.5.13",
  "vue-router": "^4.5.0",
  "vue3-apexcharts": "^1.5.2"
},
"devDependencies": {
  "@nuxtjs/tailwindcss": "^6.12.2",
  "@tailwindcss/forms": "^0.5.9",
  "@tailwindcss/nesting": "^0.0.0-insiders.565cd3e",
  "@tailwindcss/typography": "^0.5.15",
  "autoprefixer": "^10.4.20",
  "nuxt-anchorscroll": "^1.0.3",
  "postcss": "^8.4.49",
  "postcss-import": "^16.1.0",
  "prettier": "^3.3.3",
  "tw-colors": "^3.3.2"
}

Thank you in advance for your help!

Change background color of bootstrap button after dropdown selection

In my Flask web app I am using bootstrap 4 dropdown buttons where the html for one of the buttons looks like:

      <div class="dropdown">
        <button class="btn btn-secondary dropdown-toggle" style="{{ buttoncolor }}" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Valdez
        </button>
        <div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
          <a class="dropdown-item" href="{{ url_for('ak.valdez_stormtracker') }}">Storm Tracker</a>
          <a class="dropdown-item" href="{{ url_for('ak.valdez_seasontracker') }}">Season Tracker</a>
        </div>
      </div>

I would like the button’s background color to change when the url of the page matches one of the url’s of the dropdown options.

I have achieved this on regular buttons (no dropdown) as viewed here:
https://www.snowpacktracker.com/btac/

This is done by using custom.js with:

    // Handles the active state transition on bootstrap nav bar
    // get current URL path and assign 'active' class
    var pathname = window.location.pathname;
    console.log(pathname);

    $('.nav > li > a[href="'+pathname+'"').children().addClass('active')

And with some custom css:

.btn-secondary:not(:disabled):not(.disabled).active {
  background-color: var(--color);
}

In this case, the button is wrapped in an <a> tag:

          <li class="nav-item">
            <a href="{{ btnurl }}">
              <button class="btn btn-secondary" style="{{ buttoncolor }}">{{btntxt}}</button>
            </a>
          </li>

I am unable to find a similar solution that will work for the dropdown case. Although recognizing the URL similar to above would be ideal, it would probably also work just to change the background color of the button if any dropdown item is clicked (and retain the color when the new URL is loaded).

Issue with layout, vertical scrolling on body element and a table with horizontal scrolling & sticky headers

I have overflow-y auto on body and a content which contains a table.
there is a div that contains the table and it has overflow-x auto for horizontal scrolling in table view.
the table has a thead with position sticky and top 0.
My current issues:

  1. If I add the overflow-x auto to the div table container then thead sticky positioning is not working (it wont stick to the table top upon y axis scrolling).
  2. If I change thead to fixed position it does work but creates another issue, it mess up the width of the thead container because fixed is based to screen view port and not relative to parent.

How can I do it?

Looping carousel doesn’t display overhanging ‘next’ image until navigation is clicked

I have a carousel that continuously loops, the next/previous slides move into view when clicking the relevant navigation link. For this I am using Keen Slider.

The edges of the next/previous image can be seen as overhanging edges on the left/right edges of the viewport.

The problem I have is, initially this works well but when you reach ‘Slide 8’, which is the end of the original group of slides, there is a gap on the right edge when the ‘next’ slide should be.

This won’t appear until you click the “Next” navigation link, when it jumps into view. It never appears to be an issue with the left edge (previous) slides, only the slides coming into view from the right edge, after you initially reach ‘Slide 8’.

As an aside, if you set the number of visible slides preView to 5 (example below) you don’t see the edge of the “Next” slide on load, just after clicking the navigation – but 4 seems to work ok before the loop and reaching Slide 8 – not sure if it’s relevant but thought I’d document.

'(min-width: 1024px)': {
    slides: {
        perView: 4,
        spacing: 8
    }
}

This wouldn’t be an issue if I had overflow: hidden on the carousel but as I want to see the edges of the next/previous slide this isn’t an option.

Commented Out JS

You might see some commented out javascript. I was thinking it could be cool to have the carousel autoplay, then drop after either the next/previous links are clicked – but that’s very much next steps and I’m not sure on that yet. Mentioning just incase people wondered why it’s there.

/* Lazy Load Effect */

const pixelImage = document.querySelectorAll(".pixel-load")

pixelImage.forEach(div => {
  const img = div.querySelector("img")

  function loaded() {
    div.classList.add("loaded")
  }

  if (img.complete) {
    loaded()
  } else {
    img.addEventListener("load", loaded)
  }
})


/* Keen Slider */

// var animation = { duration: 40000, easing: (t) => t }
new KeenSlider("#gallery-slider", {
  loop: true,
  mode: "free-snap",
  slides: {
    perView: 1.5,
    renderMode: "precision",
    spacing: 8
  },
  breakpoints: {
    '(min-width: 768px)': {
      slides: {
        perView: 3,
        spacing: 8
      }
    },
    '(min-width: 1024px)': {
      slides: {
        perView: 4,
        spacing: 8
      }
    }
  },
  created: function(instance) {
    document.getElementById("gallery-slider").classList.add("loaded");
    //s.moveToIdx(4, true, animation);
    document
      .getElementById("arrow-left")
      .addEventListener("click", function() {
        instance.prev();
      });
    document
      .getElementById("arrow-right")
      .addEventListener("click", function() {
        instance.next();
      });
  }
  // updated(s) {
  //    s.moveToIdx(s.track.details.abs + 4, true, animation);
  // },
  // animationEnded(s) {
  //    s.moveToIdx(s.track.details.abs + 4, true, animation);
  // }
});
/* ==========================================================================
   #BASE
   ========================================================================== */

html {
  font-size: 62.5%;
  margin: 0;
  padding: 0;
}

body {
  font-size: 12px;
  font-family: "Arial", sans-serif;
  margin: 0;
  padding: 64px 0 0;
  text-transform: uppercase;
}

h2 {
  font-size: 12px;
  font-weight: 400;
  margin: 0 16px 16px;
  padding: 0;
}

figure {
  margin: 0;
  padding: 0;
}

img {
  height: auto;
  width: 100%;
  max-width: 100%;
}


/* ==========================================================================
   #KEEN SLIDER
   ========================================================================== */

.keen-slider {
  display: flex;
  align-content: flex-start;
  overflow: hidden;
  position: relative;
  touch-action: pan-y;
  user-select: none;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}

.keen-slider .keen-slider__slide {
  min-height: 100%;
  overflow: hidden;
  position: relative;
  width: 100%;
}


/* ==========================================================================
   #GALLERY
   ========================================================================== */


/**
 * My overrides for the Keen Slider gallery.
 *
 * 1. Remove `overflow: hidden` from the slider and add it to the parent. This
 *    allows the slider to align with the grid but also bleed off the edges of
 *    the page.
 * 2. Align container with the global grid.
 */

.gallery {
  margin-bottom: 64px;
  overflow: hidden;
  /* [1] */
  padding: 0 32px;
  /* [2] */
}

.gallery .keen-slider {
  overflow: visible;
  /* [1] */
}


/**
 * As the widths for each slide are set in Javascript. We add widths to slides
 * before `.keen-slider` has loaded to keep the layout consistent and help with
 * the Cumulative Layout Shift (CLS) and performance.
 */

.keen-slider:not(.loaded) .keen-slider__slide {
  width: calc((100vw / 1.5) - 24px);
}

@media(min-width: 48em) {
  .keen-slider:not(.loaded) .keen-slider__slide {
    width: calc((100vw - 48px) / 3);
  }
}

@media(min-width: 64rem) {
  .keen-slider:not(.loaded) .keen-slider__slide {
    width: calc((100vw - 56px) / 4);
  }
}

/**
 * Navigation for the gallery (prev/next).
 */

.gallery__nav {
  display: flex;
  justify-content: space-between;
  margin: 0 0 16px;
  width: 100%;
}

.gallery__nav .arrow {
  cursor: pointer;
  user-select: none;
}


/* ==========================================================================
   #PIXEL LOAD
   ========================================================================== */


/**
 * Add a pixelated effect to images while the load.
 */

.pixel-load {
  overflow: hidden;
  position: relative;
}

.pixel-load__preload img {
  image-rendering: pixelated;
  position: absolute;
  inset: 0;
  opacity: 1;
  pointer-events: none;
}

.loaded .pixel-load__preload img {
  animation: loaded .32s .16s steps(1, end) both;
}

@keyframes loaded {
  0% {
    scale: 2;
  }

  33% {
    scale: 1.5;
  }

  66% {
    scale: 1;
  }

  100% {
    opacity: 0;
    z-index: 1;
  }
}
<script src="https://cdn.jsdelivr.net/npm/[email protected]/keen-slider.min.js"></script>
<!-- Keen Slider -->
<div class="gallery">
  <div class="gallery__nav grid">
    <div class="grid__col">
      <a id="arrow-left" class="arrow arrow--left shuffle">Previous</a>
    </div>
    <div class="grid__col">
      <a id="arrow-right" class="arrow arrow--right shuffle">Next</a>
    </div>
  </div>
  <div id="gallery-slider" class="keen-slider">
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 1" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 1</figcaption>
      </figure>
    </div>
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 2" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 2</figcaption>
      </figure>
    </div>
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 3" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 3</figcaption>
      </figure>
    </div>
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 4" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 4</figcaption>
      </figure>
    </div>
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 5" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 5</figcaption>
      </figure>
    </div>
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 6" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 6</figcaption>
      </figure>
    </div>
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 7" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 7</figcaption>
      </figure>
    </div>
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 8" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 8</figcaption>
      </figure>
    </div>
  </div>
</div>
<!-- End Keen Slider -->

request.getParameter method gives null when form data submitted using javascript to servlet, why?

Here is form in JSP

<div class="col-lg-7">
    <form action="FormServlet" method="post" id="contact-form" data-aos="fade-up" data-aos-delay="200">
        <div class="row gy-4">
            <div class="col-md-6">
                <label for="name-field" class="pb-2">Your Name</label>
                <input type="text" name="firstname" id="name-field" class="form-control">
            </div>
            <div class="col-md-6">
                <label for="email-field" class="pb-2">Your Email</label>
                <input type="email" class="form-control" name="email" id="email-field">
            </div>
            <div class="col-md-12">
                <label for="subject-field" class="pb-2">Subject</label>
                <input type="text" class="form-control" name="subject" id="subject-field">
            </div>
            <div class="col-md-12">
                <label for="message-field" class="pb-2">Message</label>
                <textarea class="form-control" name="message" rows="10" id="message-field"></textarea>
            </div>
            <div class="col-md-12 text-center">
                <div class="loading">Loading</div>
                <div class="error-message"></div>
                <div class="sent-message">Your message has been sent. Thank you!</div>
                <button type="submit">Send Message</button>
            </div>
        </div>
    </form>
</div><!-- End Contact Form -->

here is Javascript file code included in JSP file

document.getElementById('contact-form').addEventListener('submit', function (event) {
    event.preventDefault(); // Prevent the default form submission

    const form = this; // Get the form
    const formData = new FormData(form); // Create FormData object from the form

    // You can also append other fields if necessary, e.g.:
    // formData.append('customField', 'value'); 

    // Get the action URL of the form (this should be the servlet URL)
    const action = form.action;

    //const action = 'http://localhost:9090/portfolio/FormServlet' 

    // Show loading message or spinner if necessary
    //document.getElementById('responseMessage').textContent = 'Submitting...';

    // Send the form data to the servlet using Fetch API

    fetch(action, {
            method: 'POST', // HTTP method for form submission
            body: formData, // The FormData object

        })
        .then(response => response.ok) // Assuming the servlet returns JSON
        .then(data => {
            // Handle successful response from the servlet
            //document.getElementById('responseMessage').textContent = 'Form submitted successfully!';
            console.log(data); // Process response if necessary
            form.querySelector('.sent-message').classList.add('d-block');

        })
        .catch(error => {
            // Handle any error that occurs during the fetch
            //document.getElementById('responseMessage').textContent = 'Error submitting form!';
            console.error('Error:', error);
        });
});

and here is servlet

package com.pz.controller;

import java.io.IOException;
import java.io.PrintWriter;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class FormServlet
 */
public class FormServlet extends HttpServlet {
    private static final long serialVersionUID = 1 L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public FormServlet() {
        super();
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.getWriter().append("Served at: ").append(request.getContextPath());
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("firstname");
        System.out.println(name);

        if (name == null || name.isEmpty()) {
            response.getWriter().println("Name field is required.");
            return;
        }
        PrintWriter out = response.getWriter();
        out.println("OK");
    }

}

When I remove javascript file from jsp, form date get submitted to servlet and request.getParameter("firstname"); works fine and prints name on console. but when I include javascript request.getParameter("firstname"); prints null on console.

NextJS Transformers Module parse failed: Unexpected character

I need to create embeddings in NextJS 15, so I started looking into @xenova/transformers and @huggingface/transformers. It was too simple to implement in a Node script (without NextJS), but I am struggling to make this work.

After the project creation, I created an API route as usual (/app/api/route.ts) and proceeded with the given example:

import { pipeline } from '@huggingface/transformers'

export async function GET() {
    const extractor = await pipeline(
        'feature-extraction',
        'Xenova/all-MiniLM-L6-v2'
    )

    const sentences = ['This is an example sentence', 'Each sentence is converted'];
    const output = await extractor(sentences, { pooling: 'mean', normalize: true });

    console.log(output)
}

But when I visit the API URL I get this error:

./node_modules/@huggingface/transformers/node_modules/onnxruntime-node/bin/napi-v3/darwin/arm64/onnxruntime_binding.node
Module parse failed: Unexpected character ‘�’ (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

I have tried also to update the Next configuration file next.config.ts with:

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  output: 'standalone',
  serverExternalPackages: ['sharp', 'onnxruntime-node'] 
};

export default nextConfig;

I don’t really know how to proceed and implement this in the server side (API routes). If I need a loader, I don’t know how to implement it.

How to fix Blocked aria-hidden on an element in react-slick?

I’m using the react-slick slider in my React Type script app. When sliding, I get this warning in my console: Blocked aria-hidden on an element because its descendant retained focus. The focus must not be hidden from assistive technology users. Avoid using aria-hidden on a focused element or its ancestor. Element with focus: div

The mentioned div is generated by Slick Library and I can’t change it.

Here is my slider setting:export const SliderSettings = () => ({
centerMode: true,
lazyLoad: ‘ondemand’ as ‘ondemand’,
centerPadding: “30px”,
infinite: false,
slidesToShow: 1,
speed: 500,
arrows: false,
initialSlide: 0,
accessibility: false,

});

Problem accessing classroom studentSubmissions with javascript

I need to access with javascript to studend submissions of a courseWork created to by javascripts code and from de same project that I make this request. I tryed before with a .NET project and the request return the student submissions and I can to use you fields.

I show here de code:

try {
console.log("CONSOLE REGISTER: ScourseId is " + idcourse + ", and idcourseork is " + 
idcourseWork);
async () => { gapi.client.classroom.courses.courseWork.studentSubmissions.list({ 
    courseId: idcourse, courseWorkId: idcourseWork }).then(function (data2) {  
    console.log("This message is not showed because the classroom API return nothing. 
    The next code is not executed");
    var studentSubm = data2.result.studentSubmission;
    console.log(studentSubm);
  for (b = 0; b < studentSubm.length; b++) {
    console.log("Mark 1");
   if (!(studentSubm[b].state == "RETURNED")) {
    var idestudiante = studentSubm[b].userId;
                                                      
    api.client.classroom.courses.students.list({ idcourse, idcoursework, idestudiante 
    }).then(function (data3) {
        var userProfile = data3.result.profile;
        if (!(studentSubm[b].attachments == null)) {
            document.write("<div class='divcont' ><div class='divizqu' class='det1' 
            id='" + Cp.Left(studentSubm[b].title, 40) + "'>" + studentSubm[b].title + 
            "</div><div class='divdere'><button class='boton' 
            onclick=enviaridstudentsubmission('" + idcourse + "','" +                                                                    
            courseWorks[p].id + ",'" + studentSubm[b].id + "')>Ver</button></div> 
            </div>n");
        }
   });
  }
  }
 });
}
} catch (err) {
    console.log(err.message);                                        
    return;
}

Browser register console

Any error is not returned. The brower register console show the courseId and the idcourseWork. They are corrects.This line stoping de execution:

   api.client.classroom.courses.students.list({ idcourse, idcoursework, idestudiante }).then(function (data3)

However I revised every word and every letter. It is maked that similar mode that other methods that run ok.

Before this register show the field “associatedWithDeveloper” that with “true” value.

I shouldn’t have any problems accessing the submissions list, but if I can, when I can do it from a .NET client with the same project.

The HTML page contains all the necessary Classroom API permissions to perform this access. This cause can be ruled out. It doesn’t return that error either.

Nextjs next build fails when I have svgr svg component

import * as Brands from '@/components/icons/brands'

export async function Signup() {
  const provider = { name: 'Google', icon: Brands.Google, id: 'google' }
  return <provider.icon />
}

This fails with a cryptic error message when I do a next build.

import Discord from './discord.svg'
import GitHub from './github.svg'
import Google from './google.svg'
import Microsoft from './microsoft.svg'
import Reddit from './reddit.svg'

export { Google, Reddit, GitHub, Discord, Microsoft }

this is brands.ts

<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="10 10 19.6 20" width="24" height="24">
    <path d="M29.6 20.2273C29.6 19.5182 29.5364 18.8364 29.4182 18.1818H20V22.05H25.3818C25.15 23.3 24.4455 24.3591 23.3864 25.0682V27.5773H26.6182C28.5091 25.8364 29.6 23.2727 29.6 20.2273Z" fill="#4285F4" />
    <path d="M20 30C22.7 30 24.9636 29.1045 26.6181 27.5773L23.3863 25.0682C22.4909 25.6682 21.3454 26.0227 20 26.0227C17.3954 26.0227 15.1909 24.2636 14.4045 21.9H11.0636V24.4909C12.7091 27.7591 16.0909 30 20 30Z" fill="#34A853" />
    <path d="M14.4045 21.9C14.2045 21.3 14.0909 20.6591 14.0909 20C14.0909 19.3409 14.2045 18.7 14.4045 18.1V15.5091H11.0636C10.3864 16.8591 10 18.3864 10 20C10 21.6136 10.3864 23.1409 11.0636 24.4909L14.4045 21.9Z" fill="#FBBC04" />
    <path d="M20 13.9773C21.4681 13.9773 22.7863 14.4818 23.8227 15.4727L26.6909 12.6045C24.9591 10.9909 22.6954 10 20 10C16.0909 10 12.7091 12.2409 11.0636 15.5091L14.4045 18.1C15.1909 15.7364 17.3954 13.9773 20 13.9773Z" fill="#E94235" />
</svg>

this is google.svg, rest are similar svg files

this is my next.config.mjs

/** @type {import('next').NextConfig} */
export default {
    experimental: {
        turbo: {
            rules: {
                '*.svg': {
                    loaders: ['@svgr/webpack'],
                    as: "*.js",
                }
            }
        }
    }
};

svgr version: “@svgr/webpack”: “^8.1.0”

type

Typescript resolves the component properly and it runs in development mode successfully, fails with the below error message when trying to build though.

(venv) iktpwsl@iktp:~/code/personal/wsd/wsd-frontend$ npm run build

> [email protected] build
> next build

  ▲ Next.js 14.2.16
  - Experiments (use with caution):
    · turbo

(node:326292) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
(Use `node --trace-warnings ...` to show where the warning was created)
   Creating an optimized production build ...
(node:326617) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
(Use `node --trace-warnings ...` to show where the warning was created)
 ✓ Compiled successfully
 ✓ Linting and checking validity of types
 ✓ Collecting page data
   Generating static pages (0/13)  [    ]Error: Unsupported Server Component type: {...}
    at e (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:137966)
    at ek (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:138016)
    at Object.toJSON (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135626)
    at stringify (<anonymous>)
    at eP (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142090)
    at eE (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142569)
    at Timeout._onTimeout (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135346)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7) {
  digest: '3007206190'
}
Error: Unsupported Server Component type: {...}
    at e (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:137966)
    at ek (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:138016)
    at Object.toJSON (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135626)
    at stringify (<anonymous>)
    at eP (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142090)
    at eE (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142569)
    at Timeout._onTimeout (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135346)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7) {
  digest: '3007206190'
}
Error: Unsupported Server Component type: {...}
    at e (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:137966)
    at ek (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:138016)
    at Object.toJSON (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135626)
    at stringify (<anonymous>)
    at eP (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142090)
    at eE (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142569)
    at Timeout._onTimeout (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135346)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7) {
  digest: '3007206190'
}
Error: Unsupported Server Component type: {...}
    at e (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:137966)
    at ek (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:138016)
    at Object.toJSON (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135626)
    at stringify (<anonymous>)
    at eP (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142090)
    at eE (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142569)
    at Timeout._onTimeout (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135346)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7) {
  digest: '3007206190'
}
Error: Unsupported Server Component type: {...}
    at e (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:137966)
    at ek (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:138016)
    at Object.toJSON (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135626)
    at stringify (<anonymous>)
    at eP (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142090)
    at eE (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142569)
    at Timeout._onTimeout (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135346)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7) {
  digest: '3007206190'
}
Error: Unsupported Server Component type: {...}
    at e (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:137966)
    at ek (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:138016)
    at Object.toJSON (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135626)
    at stringify (<anonymous>)
    at eP (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142090)
    at eE (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142569)
    at Timeout._onTimeout (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135346)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7) {
  digest: '3007206190'
}
Error: Unsupported Server Component type: {...}
    at e (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:137966)
    at ek (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:138016)
    at Object.toJSON (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135626)
    at stringify (<anonymous>)
    at eP (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142090)
    at eE (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142569)
    at Timeout._onTimeout (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135346)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7) {
  digest: '3007206190'
}
Error: Unsupported Server Component type: {...}
    at e (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:137966)
    at ek (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:138016)
    at Object.toJSON (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135626)
    at stringify (<anonymous>)
    at eP (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142090)
    at eE (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142569)
    at Timeout._onTimeout (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135346)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7) {
  digest: '3007206190'
}
Error: Unsupported Server Component type: {...}
    at e (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:137966)
    at ek (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:138016)
    at Object.toJSON (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135626)
    at stringify (<anonymous>)
    at eP (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142090)
    at eE (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142569)
    at Timeout._onTimeout (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135346)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7) {
  digest: '3007206190'
}
Error: Unsupported Server Component type: {...}
    at e (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:137966)
    at ek (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:138016)
    at Object.toJSON (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135626)
    at stringify (<anonymous>)
    at eP (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142090)
    at eE (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142569)
    at Timeout._onTimeout (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135346)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7) {
  digest: '3007206190'
}
Error: Unsupported Server Component type: {...}
    at e (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:137966)
    at ek (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:138016)
    at Object.toJSON (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135626)
    at stringify (<anonymous>)
    at eP (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142090)
    at eE (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142569)
    at Timeout._onTimeout (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135346)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7) {
  digest: '3007206190'
}
   Generating static pages (5/13)  [=   ]
Error occurred prerendering page "/auth/signup". Read more: https://nextjs.org/docs/messages/prerender-error

Error: Unsupported Server Component type: {...}
    at e (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:137966)
    at ek (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:138016)
    at Object.toJSON (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135626)
    at stringify (<anonymous>)
    at eP (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142090)
    at eE (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142569)
    at Timeout._onTimeout (/home/iktpwsl/code/personal/wsd/wsd-frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135346)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7)
 ✓ Generating static pages (13/13)

> Export encountered errors on following paths:
        /(app)/auth/signup/page: /auth/signup
(venv) iktpwsl@iktp:~/code/personal/wsd/wsd-frontend$

If I remove the provider.icon and put something else as an element, it works fine. I’ve stripped everything else from the component to reproduce it as purely as I can.

How to block message submission on “Enter” key in a ChatGPT function while using addEventListeners?

I am developing a Chrome extension that intercepts messages sent to ChatGPT and processes them before allowing submission. My goal is to block message submission when the “Enter” key is pressed unless a certain condition is met (handled by an asynchronous shouldProceedComponent function).

function addEventListeners(
  textarea: HTMLTextAreaElement | null,
  button: HTMLButtonElement | null
): void {
  textarea?.addEventListener('keydown', (event) => {
    void (async () => {
      if (event.isTrusted && event.code === 'Enter' && !event.shiftKey) {
        // Stop the event from propagating
        event.stopPropagation();
        event.preventDefault();
        
        const proceed = await shouldProceedComponent(textarea);
        if (proceed) {
          button?.click();
          chrome.runtime.sendMessage({ detections: 0 });
        }
      }
    })();
  });
}

Issue:

When pressing “Enter,” the message submission gets blocked as expected, but the button’s click event doesn’t always trigger as intended. Additionally, I’m not sure if event.stopPropagation() and event.preventDefault() are correctly applied to ensure proper functionality.

What I have tried:

  1. Debugging the asynchronous shouldProceedComponent function to confirm it returns the expected value.
  2. Checking if event.isTrusted is true to prevent artificial events from being handled.
  3. Using event.stopPropagation() and event.preventDefault() to block the default behavior of the “Enter” key.

Question:
How can I reliably block message submission by pressing “Enter” while properly ensuring the button click event triggers if the shouldProceed function returns true?

Any guidance or suggestions would be greatly appreciated!