Threads on a platform that has no threads
Why it breaks
A Shopify comment has an author, an email, a body and a status — and nothing else. There is no parent field and comments cannot carry metafields, so a team reply posted through the API is indistinguishable from an unrelated top-level comment, and the conversation reads out of order.
What I did
Each team reply records the comment it answers in its own email address, using plus-addressing on the team inbox. Mail to that address still reaches the team, and the email is never shown on the site or in the app. When the list is built, replies are nested under their parent — only on the same post, and never under another staff comment — and a parent that falls on the next page is fetched in so the thread is complete. If any of that fails, the list still renders flat.
export function teamEmailFor(parentId, env = process.env) {
const base = staffEmail(env);
const id = numericId(parentId);
const at = base.lastIndexOf("@");
return id && at > 0 ? `${base.slice(0, at)}+${id}${base.slice(at)}` : base;
}
export function parseReplyTarget(email) {
const match = /^[^+@\s]+\+(\d{1,20})@/.exec(clean(email));
return match ? match[1] : null;
}