Why does attributes work in useContent but not in fetchContent on the server?
In my client components I pass attributes to useContent and my audience matches fine:
const {content} = useContent('promo-banner', { attributes: {plan: 'pro'},});I copied the same options object into a server call and the variable stops reaching the evaluation, the audience never matches:
const {content} = await fetchContent('promo-banner', { attributes: {plan: 'pro'},});Is the API actually different on the server side? Thanks in advance.
2 answers
The shape is different between the two. On the server, fetchContent takes attributes nested inside a context object, not at the top level:
const {content} = await fetchContent('promo-banner', { context: { attributes: {plan: 'pro'}, },});In React, useContent takes attributes directly on the options object, which is what you had. That mismatch is the usual reason variables silently fail to reach the evaluation after moving a call to the server.
The reason it fails quietly rather than erroring is that undefined variables evaluate to false by design. When the attribute lands in the wrong place, your CQL condition sees an undefined variable, evaluates to false, and the audience just does not match. See the context option on fetchContent for the server shape, and the useContent hook reference for the client one.
Ran into the exact same thing porting a hook to a server component. Moving the attributes under context fixed it for me too, the audience started matching immediately.