Loosen post source constraints (#8478)

* Loosen post source constraints

* logger warn if failed to find source

* Tweak assertion logic

---------

Co-authored-by: Eric Bailey <git@esb.lol>
This commit is contained in:
Samuel Newman
2025-06-12 01:22:21 +03:00
committed by GitHub
parent 093454f5b2
commit 18b258d060
+10 -5
View File
@@ -34,7 +34,7 @@ const consumedSources = new Map<string, PostSource>()
* Used for FeedFeedback and other ephemeral non-critical systems.
*/
export function setUnstablePostSource(key: string, source: PostSource) {
assertValid(
assertValidDevOnly(
key,
`setUnstablePostSource key should be a URI containing a handle, received ${key} — use buildPostSourceKey`,
)
@@ -51,9 +51,10 @@ export function setUnstablePostSource(key: string, source: PostSource) {
export function useUnstablePostSource(key: string) {
const id = useId()
const [source] = useState(() => {
assertValid(
assertValidDevOnly(
key,
`consumeUnstablePostSource key should be a URI containing a handle, received ${key} — use buildPostSourceKey`,
`consumeUnstablePostSource key should be a URI containing a handle, received ${key} — be sure to use buildPostSourceKey when setting the source`,
true,
)
const source = consumedSources.get(id) || transientSources.get(key)
if (source) {
@@ -87,11 +88,15 @@ export function buildPostSourceKey(key: string, handle: string) {
/**
* Just a lil dev helper
*/
function assertValid(key: string, message: string) {
function assertValidDevOnly(key: string, message: string, beChill = false) {
if (__DEV__) {
const urip = new AtUri(key)
if (urip.host.startsWith('did:')) {
throw new Error(message)
if (beChill) {
logger.warn(message)
} else {
throw new Error(message)
}
}
}
}