Skip to content

[bug]: Function logic issue in masonry.tsx #277

Description

@wxul

Describe the bug

see: https://github.com/sadmann7/diceui/blob/main/docs/registry/bases/base/ui/masonry.tsx#L923

function onRafSchedule<T extends unknown[]>(
  callback: (...args: T) => void,
): OnRafScheduleReturn<T> {
  let lastArgs: T = [] as unknown as T;
  let frameId: number | null = null;

  function onCallback(...args: T) {
    lastArgs = args;

    if (frameId)  //  This function will never be executed. Is the correct way to write it if (!frameId)?
      frameId = requestAnimationFrame(() => {
        frameId = null;
        callback(...lastArgs);
      });
  }

  onCallback.cancel = () => {
    if (!frameId) return;
    cancelAnimationFrame(frameId);
    frameId = null;
  };

  return onCallback;
}

How to reproduce

https://github.com/sadmann7/diceui/blob/main/docs/registry/bases/base/ui/masonry.tsx#L923

Link to reproduction

https://github.com/sadmann7/diceui/blob/main/docs/registry/bases/base/ui/masonry.tsx#L923

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions