(React) Inline HTML leaves detached DOM; React component doesn’t

When we render some nodes conditionally(ex. {expanded && <>...</>}), HTML element leaves detached DOM, but React Components doesn’t.

Example

e.g.

...
return <>
  ...
  {expanded && <div id="inlined">Foo</div>
</> 

If the expanded state goes false -> true -> false, the elements in right side will be inserted and removed from DOM.
After that, <div id="inlined">Foo</div> left as detached DOM.

But, when I make them as seperated component:

function Foo() {
  return <div id="seperated">Foo</div>
}

and, doing something like previous one but using <Foo /> component instead of inline HTML element:

...
return <>
  ...
  {expanded && <Foo />
</> 

It does not leave detached DOM.

detached DOM snapshot from Chrome DevTools

this is detached DOM snapshot from Chrom DevTools

And I wonder that..

What’s difference between using inline <div>(or other HTML elements) and wrapping/seperating into a component?
I would like to know the exact explanation for this phenomenon.

More Examples with CodeSandbox you can see

Visit https://q4g5mg.csb.app/ , click the button twice, to expand/collapse, and then make a snapshot

Full code of example is below:

import { useState } from "react";
import "./App.css";

const dummyArrays = Array.from({ length: 100 });
const Dummy = () => {
  return (
    <ul>
      {dummyArrays.map((_, index) => (
        <li key={index}>{index}</li>
      ))}
    </ul>
  );
};

function WowList() {
  return (
    <ul id="wow-list">
      <li>WOW</li>
      <li>WOW</li>
      <li>WOW</li>
      <li>WOW</li>
      <li>WOW</li>
    </ul>
  );
}


export default function App() {
  const [expanded, setExpanded] = useState(false);

  return (
    <>
      <button
        onClick={() => {
          setExpanded((prev) => !prev);
        }}
      >
        {expanded ? "close" : "open"}
      </button>
      {expanded && (
        <>
          <div id="this-dummy-remains-detached-dom">
            <Dummy />
          </div>
          <div id="this-div-also-remains-attached-dom">
            <p>Detached DOM Elements problem test</p>
          </div>
          <WowList />
        </>
      )}
    </>
  );
}

before

^ Snapshot: before expand/collapse

after

^ Snapshot: after expand/collapse

<WowList /> does not remained detached DOM, but the rest of them (under the <div>, regardless of whether it’s an HTML element or component)

Waiting for a clear answer to this. Thanks!

Drizzle ORM + Postgres, how to specify Postgres database Schema? defaults to public

I am trying to set connection to Postgres from Drizzle, but I cannot set the schema name in the connection string

I tried
postgres://localhost:5432/mydatabase?searchpath=myschema

postgres://localhost:5432/mydatabase?currentSchema=myschema

postgres://localhost:5432/mydatabase.myschema

none of these worked.
Drizzle would still connect to the default public schema, which Postgres documenntation advice not to use
Also, there is no concept of a public schema in the SQL standard. For maximum conformance to the standard, you should not use the public schema.https://www.postgresql.org/docs/current/ddl-schemas.html

Also on Drizzle docs for connection string they don’t specify how to choose schema, using this keyword in general is very confusing in the Drizzle echo system as it usually lead to answers about defining the drizzle typescript schema.
https://orm.drizzle.team/docs/connect-overview

How to retrieve the visible content of multiple `select` elements at once?

I want to retrieve the visible text content of an div element which contains several <select> elements:

However, div.innerText will include text content in all <option> tags, including unselected ones (and to my surprise, even hidden ones are included as well).

let div=document.querySelector("div")
console.log("div.innerText:n"+div.innerText)
select {
  appearance: none;
  border: none
}
<div id="div">
  <select>
    <option selected>Alice</option>
    <option>Bob</option>
    <option hidden>Carol</option>
  <select>
  -
  <span>
    <!-- the dom tree could be complicated -->
    <span>
      <select>
        <option>Alice</option>
        <option selected>Bob</option>
      <select>
    </span>
  </span>
</div>

What I want is simple Alice - Bob.

Is it possible to make it?

switch company trigger in odoo 17

suit to my work i need to trigger a method when the user switch company , i tried overrideing the write method in res.user model but i didn’t work i tried with js like this :

/** @odoo-module **/

import { rpc } from "@web/core/network/rpc_service";

document.addEventListener("click", function (event) {
    if (event.target.closest(".o_switch_company_menu .dropdown-item[data-company-id]")) {
        const companyId = event.target.closest(".dropdown-item").dataset.companyId;
        rpc("/dashboard_commission/switch_company", {
            company_id: companyId,
        }).then(function () {
            alert("hello world");
        });
    }
});

but still i didn’t acheive my goal … if any one have an idea how to trigger a method when the user switch company i would be thankful.

Can’t pause audio

I’m working on a project, and I can’t seem to pause the audio once it starts playing. This is the code I’m running right now:

// <<backmus start 01>>
var executeBackgroundMusic = function(action)
{
  var operator = action.options[0]
  var song = music[action.options[1]];
  var audio = new Audio(music[action.options[1]]);
  if (operator == "start"){
    audioPlayer["currentlyPlaying"] = song;
    audio.play();
    audio.loop=true;
  }
  else if (operator == "stop") {
    audio.pause();
    audio.currentTime = 0;
    audioPlayer["currentlyPlaying"] = "";
  }
}

The <<backmus start 01>> is how I am calling the function, and the song’s ID is 01. When I execute the code, the song starts playing when it is supposed to. When I prompt <<backmus stop 01>>, however, the song keeps playing. I know it goes through the code, though, because audioPlayer["currentlyPlaying"] is set to "" in the console. The start operator works properly, so I don’t think that part is the issue. Is there another way to stop audio besides audio.pause()?

How can I animate opacity on a parent container while preserving backdrop-filter: blur() on child elements during the animation?

I’m trying to animate a parent container using a keyframe-based opacity fade-in/out (@keyframes fadeIn and fadeOut). Inside the container, there are child elements with backdrop-filter: blur(…) applied to achieve a frosted-glass effect.

Here’s a simplified version of the setup:

<div id="myContainer" class="container">
    <div class="shape-div"></div>
    <!-- more elements may be added here in the future -->
</div>


.shape-div {
    width: 400px;
    height: 400px;
    border-radius: 12px;
    background-color: rgba(0, 128, 0, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
.fade-in {
    animation: fadeIn 2s forwards;
}
.fade-out {
    animation: fadeOut 2s forwards;
}

The issue:
When I animate the parent container (#myContainer) using a fade-in/out animation on its opacity, the backdrop-filter on the .shape-div breaks or disappears during the animation, especially in Chrome and others. The blur only works when not nested inside an element with an animated opacity.

I understand that animating opacity on the same element as backdrop-filter works fine, but:

•   I have (or will have) many children in the container.

•   I want to keep the animation logic at the container level to avoid applying animation to each child individually.

•   I want to avoid complex JS-based fade management per child, for maintainability.

What I’m looking for:

How can I:

•   Animate the parent container’s opacity using CSS keyframes,

•   And still have the blur effect on child elements render properly throughout the animation?

Any workaround that maintains clean structure and future extensibility is welcome — whether it involves z-index layering, stacking context tricks, or best practices for isolating backdrop-filter from animation impact.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Toggle Container with Keyframe Fade</title>
    <style>
        body {
            margin: 0;
            height: 100vh;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            gap: 20px;
            font-family: sans-serif;
            background-image: url('https://picsum.photos/1200/800');
            background-repeat: no-repeat;
            background-position: center;
            background-size: cover;
        }
        
        .container {
            display: inline-block;
            position: relative;
        }
        
        .shape-div {
            width: 400px;
            height: 400px;
            
            border-radius: 12px;
            background-color: rgba(0, 128, 0, 0.5);
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
        }
        
        button {
            padding: 10px 20px;
            font-size: 16px;
            cursor: pointer;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; }
            to   { opacity: 1; }
        }
        
        @keyframes fadeOut {
            from { opacity: 1; }
            to   { opacity: 0; }
        }
        
        .fade-in {
            animation-name: fadeIn;
            animation-duration: 2s;
            animation-fill-mode: forwards;
        }
        
        .fade-out {
            animation-name: fadeOut;
            animation-duration: 2s;
            animation-fill-mode: forwards;
        }
        
    </style>
</head>
<body>
    
    <div id="myContainer" class="container">
        <div id="myShape" class="shape-div"></div>
    </div>
    
    <button onclick="toggleContainer()">Toggle Container</button>

    <script>
        let isVisible = true;
        const container = document.getElementById('myContainer');
        
        function toggleContainer() {
            
            if (isVisible) {
                container.classList.remove('fade-in');
                container.classList.add('fade-out');
            } else {
                container.classList.remove('fade-out');
                container.classList.add('fade-in');
            }
            
            isVisible = !isVisible;
            
        }
    </script>
    
</body>
</html>

Meta Tags Not Displaying Properly?

I have a self-image host I made with Amazon S3 and a Cloudflare worker, mainly for Discord. When I send links to images, it does not show my image at all, but it does show some of the other meta tags I have put in. The code is below:

async function handleRequest(request) {
  const userAgent = request.headers.get("user-agent");
  if (userAgent && userAgent.includes("Discord")) {
    const response = await fetch(request);
    if (response.status == 200) {
      const contentType = response.headers.get("content-type");
      if (contentType && contentType.startsWith("image/")) {
        const url = new URL(request.url);
        var date2 = new Date().toLocaleString("en-US", {timeZone: "America/Vancouver"});
        const filename = decodeURIComponent(url.pathname.slice(url.pathname.lastIndexOf("/") + 1));
        const title = "spheu.ca";
    //  const description = `File ID: ${filename}`;
        var randomColor = '#'+Math.floor(Math.random()*16777215).toString(16);
        const color = `${randomColor}`;
    
        return new Response(`<html>

<head>
  <title>${title}</title>
  <meta charset="utf-8"></meta>
  <meta property="og:site_name" content="Random Hex Code: ${color}">
  <meta name="robots" content="noindex">
  <meta name="theme-color" content="${color}">
  <meta name="og:title" content="${title}">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:image" content="${url.toString()}" />
<body>
  <img src="${url.toString()}">
</body>
</html>`, {
          headers: {
            "Content-Type": "text/html; charset=UTF-8"
          }
        });
      }
    }
    return response;
  }
  return fetch(request);
}

addEventListener("fetch", event => {
  event.respondWith(handleRequest(event.request));
});

Instead of populating with the image that was uploaded with the twitter:card and twitter:image tags, it appears like this. Any help would be appreciated, TIA 🙂

Can two equivalent JavaScript generators be derived from each other?

I have two JavaScript generator functions for permutations and I would like to understand their relative merits.

From Robert Sedgewick‘s paper, Permutation Generation Methods (1977), we obtain the basic recursive algorithm on page 140:

To generate all permutations of P[1], • • •, P[N], we repeat N times the step: “first generate all permutations of P[1], •••, P[N-1], then exchange P[N] with one of the elements P[1], •••, P[N-1].”

A first JavaScript generator function can be derived like this:

function* permutations(n) {
    if (n == 1) yield P;
    else {
        for (let i = 1; i <= n; i++) {
            yield* permutations(n - 1);
            if (i < n) swap(n, heap(n, i));
        }
    }
}

Note that I have added the obvious recursion base case n==1 and a routinely chosen position of the yield statement. Also, to avoid “unnecessary” swaps during the last iteration of the for loop, there is the guard if (i < n). In this way, it seems to be equivalent to Heap‘s recursive algorithm given in Wikipedia. In any case, when called for N = 4 it reproduces Heap‘s enumeration as given in Sedgewick’s paper.

The following code is needed to run the generator:

var P = [], N, count; 

function swap(x, y) { let t = P[x]; P[x] = P[y]; P[y] = t }
function heap(n, i) { return (n % 2) || i }

N = 4;
for (let i = 1; i <= N; i++) P[i] = i;
count = 1;
for (p of permutations(N)) console.log(count++, ":", p.slice(1));

The other generator is this one:

function* permutations(n) {
    if (n > 1) {
        for (let i = 1; i <= n; i++) {
            yield* permutations(n - 1);
            if (i < n) { swap(n, heap(n, i)); yield P }
        }
    }
}

The main difference is the position of the yield statement, which was found “by inspection” (hard thinking), and the (apparently) missing base case, because it simply returns and does nothing.

This generator returns the same sequence of permutations as the first one, with one exception: the initially given permutation is not yielded, but must be treated on its own.

Is there one rigorous way to formally “deduce” or “derive” one generator from the other? This is in view of the fact that they are both “the same” (more or less). Is one of them to be preferred over the other?

Cookies set in one page but cant retrive in the other

I am building a Login/Signup page and am trying to set a cookie called “username” and it is being set as well but when i try to actuallly use it in the other it doesnot work.

these are my settings of the cookie

res.cookie(“otpToken”, otpToken, {
httpOnly: true,

  secure: false,
  maxAge: 60 * 60 * 1000
});

res.cookie("username", username, {
  httpOnly: true,

  secure: true,
  maxAge: 60 * 60 * 1000
});

its sets as i tested in post man but i am having really hard time retriving it as its undefiend evertime

I want to retrive the cookie from
const username = req.cookies.username;
const otpToken = req.cookies.otpToken;

but i cant in next page

How can I build a dynamic BMI calculator using JavaScript that gives color-coded feedback based on health categories? [closed]

I’m building a fitness web app (as part of a student project) where I want to include a BMI calculator. I want the result to dynamically show color-coded health categories — for example, red for underweight or obese, green for normal, and yellow for overweight — directly below the input form after calculation.

So far, I’ve created a form with inputs for height and weight and a button to calculate BMI using JavaScript. The BMI result shows correctly, but I’m struggling with how to dynamically style the feedback text and make it update with each new calculation.

I used JavaScript DOM manipulation to display the result using innerHTML, and tried applying CSS classes conditionally based on BMI values. However, the color updates don’t consistently apply, or sometimes the previous class styling remains.

How to set up a cluster in Yandex Maps to display the sum of the values ​from the labels, and not the number of labels themselves?

I use Yandex Maps and the ObjectManager library to display markers and cluster them. Each marker contains information about the number of employees, and I need the clustering to display not just the sum of the markers, but the sum of all employees from the markers combined into a cluster.

When clustering, I only get the number of markers in the cluster, but I need the sum of the number of employees at all markers in the cluster to be displayed. How can I set up clustering correctly to show the sum of people from the markers in the cluster?

Thanks in advance for your help!

ymaps.ready(function () {
    myMap = new ymaps.Map("map", {
        center: [55.778487, 37.672379],
        zoom: 4,
        controls: ['zoomControl']
    });

    // Create ObjectManager for manage tags
    objectManager = new ymaps.ObjectManager({
        clusterize: true,
        gridSize: 32,
        clusterDisableClickZoom: false,
        clusterIconLayout: 'default#pieChart',
        clusterIconSize: [40, 40],
    });

    myMap.geoObjects.add(objectManager);

    loadInitialMapData();
});

function addMarkerToMap(city, coordinates, employees) {
    const iconContent = employees.length.toString();
    const feature = {
        type: 'Feature',
        id: city,
        geometry: {
            type: 'Point',
            coordinates: coordinates
        },
        properties: {
            hintContent: `${city} - ${employees.length} employees`,
            balloonContent: generateBalloonContent(city, employees),
            iconContent: iconContent,
            employees: employees,
        },
        options: {
            iconSize: [80, 80],
            iconColor: '#1e98ff',
            hideIconOnBalloonOpen: false,
        }
    };
    objectManager.add(feature);
}

function loadInitialMapData() {
    const response = await fetch('/map_data');
    const markers = await response.json();
    markers.forEach(marker => {
        addMarkerToMap(marker.city, marker.coordinates, marker.employees);
    });
}

Embedded website with auto translate and currency exchange [closed]

I have been helping friends and family to buy products from Chinese apps such as Alibaba, Pinduoduo and Taoboa for a small fee. This is because I have been to China and I had access to some of their local payment systems such as Wechat pay which allows me to shop at their local market remotely.

The products I buy gets shipped directly to the local address of my shipping agent which I registered as my receiving address in China. Once the item is received, my agent sends me a message and then informs me of the date of shipment to my Country. The buyer then receives his or her item in a week’s time. Many people in my country have started showing interest in this service because it helps them to buy products not available locally at an affordable price. However, since the demand is getting higher, I want to look at the possibilities of automating the system so that I don’t need to be contacted whenever somebody wants me to order something for them online.

Here is what I have in mind. I want to build a website that can display the contents from the Chinese website translated in English and the prices changed from RMB to my local currency with the addition of the service fee, let’s say 1 – 2 % of the item cost. Once the buyer chooses a product to buy, they get referred to my own payment link that accepts local payment systems in my local currency. When the payment is completed, I received a notification to place an order with the product link. Then I click on the link, pay for the product in Chinese currency using local Chinese payment methods and then have it shipped to my country through my shipping agent.

I know this sounds like it’s impossible or very hard to do but I just want to explore my possibilities.

why spawnSync give different result than the actual command

when we have a file structure like that

/foo
  /bar
    a.json
    /baz
      b.json

and then you run git ls-files foo/bar/**/* it return both a.json and b.json

but if you write a script to do that

import { spawnSync } from 'node:child_process';

const pattern = 'foo/bar/**/*';

const lsFiles = spawnSync(
    `git`,
    ['ls-files', pattern],
    {
        encoding: 'utf8',
    },
).stdout;

console.log(lsFiles);

it only return b.json but not a.json

you can test it here https://github.com/robertIsaac/spawn-reprod