I'm looking for a solution example based on npm create @shopify/hydrogen@latest scaffolded project.
I want to pass a uniquely generated attribute from the client to the cart line item. In the end it should look like this:

I'm able to generate a random id on the server side in cart.tsx like this:
...
switch (action) {
case CartForm.ACTIONS.LinesAdd:
// Add a unique attribute to each line being added to the cart
const linesWithUniqueId = inputs.lines.map((line: any) => ({
...line,
attributes: [
...(line.attributes || []),
{
key: "someUniqueId",
value: `${someUniqueId }-${new Date().getTime()}`, // Unique identifier based on timestamp
},
],
}));
result = await cart.addLines(linesWithUniqueId);
break;
...
I can see that it's possible and Shopify treats this as a unique line item which is exactly what I need. Problem is that I'm struggling to pass it over from the client. In my application there's a requirement due to some libraries we use to generate an ID on the client side and pass it over to the shopping cart item, it needs to happen on Add To Cart button click.
Code for generating this ID is below, it's essentially an API call
const someUniqueId = await session.createUniqueId();
My goal is to change the Shopify Hydrogen App code so that when the user clicks Add To Cart, the API call is fired on the client side, once the ID is returned, the line item should be added to the cart with the returned ID as an attribute.
So far, I tried changing the <AddToCartButton/> component by adding a useEffect hook that intercepts fetcher.state and overrides lines object. This has somewhat worked but but doesn't work every time. I believe I could improve my solution but that seems overengineered. I believe there must be a 'cleaner' way to achieve this.