S
SolidJS3mo ago
wes337

Solid-Meta on dynamic SSR routes

I am trying to set dynamically set metadata for Slack/X preview cards.
const getVideo = query(async (videoId) => {
"use server";
const response = await getVideo(videoId)
return { video: data.video };
}, "video");

export const route = {
preload: getVideo,
};

export default function VideoPage() {
const params = useParams();
const data = createAsync(() => getVideo(params.videoId), {
deferStream: true,
});

return (
<Suspense>
{/* This works client-side only */}
<Title>{data().video.title}</Title>
{/* ... Rest of metadata tags below and the component code ... */}
</Suspense>
);
}
const getVideo = query(async (videoId) => {
"use server";
const response = await getVideo(videoId)
return { video: data.video };
}, "video");

export const route = {
preload: getVideo,
};

export default function VideoPage() {
const params = useParams();
const data = createAsync(() => getVideo(params.videoId), {
deferStream: true,
});

return (
<Suspense>
{/* This works client-side only */}
<Title>{data().video.title}</Title>
{/* ... Rest of metadata tags below and the component code ... */}
</Suspense>
);
}
In this example, the title *does update dynamically, but only client-side. If I post this URL to Slack, the preview card gets the default <Title> which is set in my app.jsx file. Also worth noting that I have set the `og: meta tags and the twitter:*` ones too but omitted them from the example to keep it short I want people to be able to share video URLs on Slack and Twitter and elsewhere and the previews to show the dynamically generated metadata content. How can I do this? Am I missing something or is there some bug in my code?
8 Replies
Brendonovich
Brendonovich3mo ago
This should work - I've done the same as your code and got this on /some-video-id
No description
wes337
wes337OP3mo ago
Here is the actual example website: https://mde.wes.software/series/pgl/96-appreciate-every-cigarette. If you open the page, the title and the rest of the metadata does change correctly. But if you inspect it here: https://metatags.io/?url=https%3A%2F%2Fmde.wes.software%2Fseries%2Fpgl%2F96-appreciate-every-cigarette you can see it is not applied. This means that Twitter/X/Slack previews won't work as expected
wes337
wes337OP3mo ago
MDE.tv
MDE.tv
For all Sam Hyde content, sign up here. (Including the podcast with Nick, doy (this is all that stuff)).
Brendonovich
Brendonovich3mo ago
Hmm is VideoPage underneath another Suspense that's not being deferred? actually idk if that changes things since Suspense runs both branches in parallel
wes337
wes337OP3mo ago
There is a top level Suspense just after the MetaProvider in the Router
Brendonovich
Brendonovich3mo ago
Oh actually if there's a <Show> above it that triggers the Suspense then that could cause the stream to flush early
wes337
wes337OP3mo ago
Yeah, it seems to be related to that. I moved some Suspense and Show above it and it seems to work now. Thanks!
Brendonovich
Brendonovich3mo ago
Nice!

Did you find this page helpful?