treeName

tcmts.cli.rsc.treeName · #ktwnlrar · term · runs anywhere

The file a server component's tree is kept in on a static site (_app/trees/<name>.json), by what it was rendered from: the component's hash and its props, as encoded (the key __TCM_TREES__ has it by). 128 bits of four FNV-1a hashes, so the browser names it the same without crypto.subtle, which a page served over plain HTTP lacks.

export function treeName(key: string): string {
  let out = "";
  for (const seed of [0x811c9dc5, 0x01000193, 0x9e3779b9, 0x85ebca6b]) {
    let h = seed >>> 0;
    for (let i = 0; i < key.length; i++) {
      h ^= key.charCodeAt(i);
      h = Math.imul(h, 0x01000193) >>> 0;
    }
    out += h.toString(16).padStart(8, "0");
  }
  return out;
}

used by