lazy load @ipld/dag-cbor in computeCid

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-07-08 16:17:50 +03:00
parent ea3d6827c7
commit 32c8f04517
+6 -1
View File
@@ -16,7 +16,6 @@ import {
RichText, RichText,
} from '@atproto/api' } from '@atproto/api'
import {TID} from '@atproto/common-web' import {TID} from '@atproto/common-web'
import * as dcbor from '@ipld/dag-cbor'
import {t} from '@lingui/core/macro' import {t} from '@lingui/core/macro'
import {type QueryClient} from '@tanstack/react-query' import {type QueryClient} from '@tanstack/react-query'
import {sha256} from 'js-sha256' import {sha256} from 'js-sha256'
@@ -505,6 +504,12 @@ const mf_sha256 = Hasher.from({
}) })
async function computeCid(record: AppBskyFeedPost.Record): Promise<string> { async function computeCid(record: AppBskyFeedPost.Record): Promise<string> {
/*
* Lazily loaded since it's only needed when posting a thread, and its
* `cborg` dependency is ~190KB that would otherwise be in the initial
* web bundle.
*/
const dcbor = await import('@ipld/dag-cbor')
// IMPORTANT: `prepareObject` prepares the record to be hashed by removing // IMPORTANT: `prepareObject` prepares the record to be hashed by removing
// fields with undefined value, and converting BlobRef instances to the // fields with undefined value, and converting BlobRef instances to the
// right IPLD representation. // right IPLD representation.