# slider-blocks/2.11.0/src/helper/unique-id.js

GutSlider – All in One Slider and Carousel Blocks for Gutenberg, version 2.11.0. 41 lines.

- Page: https://pluginprobe.com/plugins/slider-blocks/2.11.0/code/src/helper/unique-id.js
- Raw: https://pluginprobe.com/plugins/slider-blocks/2.11.0/raw/src/helper/unique-id.js
- Modified: 2026-02-21T13:53:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/slider-blocks/2.11.0/code/src/helper/unique-id.js#L10-L20`.

```javascript
import { select } from '@wordpress/data';
export const handleUniqueId = ({ uniqueId, setAttributes, clientId }) => {
    const generateUniqueId = 'gut' + '-' + Math.random().toString(36).substr(2, 9);

    /**
     * Define and Generate Unique Block ID
     */
    if (!uniqueId) {
        setAttributes({ uniqueId: generateUniqueId });
        return;
    }

    /**
     * Assign New Unique ID when duplicate uniqueId found
     * Mostly happens when User Duplicate a Block
     */

    const allBlocks = select('core/block-editor').getBlocks();

    let duplicateFound = false;
    const fixDuplicateUniqueId = blocks => {
        if (duplicateFound) return;
        for (const item of blocks) {
            const { innerBlocks } = item;
            if (item.attributes.uniqueId === generateUniqueId) {
                if (item.clientId !== clientId) {
                    setAttributes({ uniqueId: generateUniqueId });
                    duplicateFound = true;
                    return;
                } else if (innerBlocks.length > 0) {
                    fixDuplicateUniqueId(innerBlocks);
                }
            } else if (innerBlocks.length > 0) {
                fixDuplicateUniqueId(innerBlocks);
            }
        }
    };

    fixDuplicateUniqueId(allBlocks);
};

```
