This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Open graph for Snack and example wrapper #103
Open
raedle
wants to merge
1
commit into
facebookresearch:main
Choose a base branch
from
raedle:export-D38482624
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't work at build time.
match.params
is probably an empty object there because Docusaurus does not know all the paths it has to build at build time, and it builds a single static HTML file.view-source:https://playtorch-git-fork-raedle-export-d38482624-fbopensource.vercel.app/snack/@raedle/image-classification/index.html
Note: I don't understand why you don't get something like
undefined | PlayTorch Snack
😅 that's worth opening the static HTML file locally and see what it contains.But this works at runtime, and Docusaurus is able to "fix" your wrong metadata after React is loaded and hydrated: https://playtorch-git-fork-raedle-export-d38482624-fbopensource.vercel.app/snack/@raedle/image-classification/
Unfortunately, I believe social previews require correct metadata to be set correctly at build time. They probably try to optimize their crawlers and only load the HTML file, not executing any JS.
So you really need to produce one HTML file per stack if you want social previews to work.
You can just do something like:
I don't think social previews are compatible with dynamic routes, this would require server-side rendering. Note I'm not sure it's particularly interesting to render those snacks inside Docusaurus? You could as well use a Vercel lambda to server-side rendering a similar HTML template with the Snack embed => there you could server-render the metadata you want so that the first HTML content received by the user contains the appropriate metadata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @slorber for taking the time looking into this!
The Snacks aren't static and not known in advance, which is why the following won't work in our case unfortunately :/
The dynamic
snack
route is a landing page for PlayTorch users to share their Snacks with others in the community. For example, if user A creates a Snack (e.g.,@userA/foobar
), the dynamic route is https://playtorch.dev/snack/@userA/foobar (foobar is the Snack named by the user). However, we won't know all the Snacks and Snack names that will be created by PlayTorch users.As you mentioned and looking at the docs Understanding SSR, it seems like we need to break out of Docusaurus and implement a custom service that returns SSR pages with the correct Open Graph metadata.
Thanks again for your response!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes unfortunately it looks like you can't use static site generator for this use-case.
Note that Vercel and others (Cloudflare, Netlify) have edge runtimes now, which means you can also write some code to "customize" the static HTML being served to the user. Even if the file has generic metadata, technically you could use request info to update the response and serve a different response per request.
I don't know if Vercel has that already (@leerob probably knows) but I've definitively seen this used on Cloudflare Workers: https://developers.cloudflare.com/workers/examples/modify-response/