Skip to content

[Bug?]: Setting a Signal in ResizeObserver Breaks in dev #1608

Description

@sabercoy

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Setting a signal inside ResizeObserver API causes screen to flash and blank null errors in console.

Expected behavior 🤔

It behaves fine in normal SolidJS (both dev and build)
It behaves fine in SolidStart (just the build)
I expect it to behave fine in SolidStart dev mode

Steps to reproduce 🕹

  1. Create a new SolidStart project
  2. Add this code to a page
import { createSignal, Index, onMount } from "solid-js";

const getSquaresPerRow = (containerWidth: number, squareMinWidth: number, gap: number) => {
  return Math.floor((containerWidth + gap) / (squareMinWidth + gap))
}

export default function Home() {
  const [squares] = createSignal(Array(20).fill(0))
  const [test, setTest] = createSignal(0)
  let containerRef!: HTMLDivElement

  const onContainerResize = (entries: ResizeObserverEntry[]) => {
    const newSquaresPerRow = getSquaresPerRow(entries[0].contentRect.width, 260, 2)
    setTest(newSquaresPerRow)
  }

  onMount(() => {
    new ResizeObserver(onContainerResize).observe(containerRef)
  })

  return (
    <div ref={containerRef}>
      <div style={{ 'display': 'grid', 'gap': '2px', 'grid-template-columns': `repeat(${test()}, 1fr)`}}>
        <Index each={squares()}>{square => <div style={{ 'background-color': 'gray', 'aspect-ratio': 1 }}></div>}</Index>
      </div>
    </div>
  );
}
  1. Open the console, should have errored by then, in case not resize the viewport.

Context 🔦

I am trying to use ResizeObserver in dev without getting errors
image

Your environment 🌎

Chrome on Fedora Linux
used Bun

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions