-
Notifications
You must be signed in to change notification settings - Fork 19
feat: allow declaring document used manually using meta tags #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: allow declaring document used manually using meta tags #95
Conversation
@angeloashmore, beyond the review, can you also try to check out if it's behaving as expected for you using the above toolbar script? |
This is awesome @lihbr! Sorry it took me a while to review. Everything looks great after testing. I only found one limitation that I think we should address (ignoring the private repo limitation for now, of course): Reacting documents declared at runtimeIn its current iteration, it seems like the toolbar will query for This misses any I encountered this while testing this with a Gatsby site in development mode. Gatsby client-side renders pages in development mode, meaning (It's worth noting that this isn't a problem after building the site since the HTML will include those I believe we could use a MutationObserver to accomplish this. By listening for changes to |
Here you go, updated the logic to also register a MutationObserver 🙂 Should be good now~ |
Ready for test/review now @angeloashmore 🎉 @srenault following your review I updated the following:
|
@lihbr Are you able to re-deploy the test to Netlify? Correct me if I'm wrong, but I don't think the updated Mutation Observer logic is deployed at https://prismic-toolbar-meta-predictions.netlify.app/prismic-toolbar/4.0.7/prismic.js?repo=YOUR_REPO&new=true |
Here you go! My bad |
Thanks! 🙏 It's working great for me now. I think it's good to merge and deploy (pending approval from others on the team). Related: I found an issue in the way In the following example, only the last document in the {isFilled.group(page.data.related_pages) && (
<ul>
{page.data.related_pages.map((item) => {
const document = item.related_page.document;
return (
document && (
<li key={document.prismicId}>
<Helmet>
<meta
name="prismic-documents"
content={document.prismicId}
/>
</Helmet>
<PrismicLink href={document.url}>
{document.prismicId} — {document.data.title.text}
</PrismicLink>
</li>
)
);
})}
</ul>
)} We may need to provide an abstraction for React and/or Gatsby users. Even with this limitation, I believe Note that Next.js does not perform this overriding automatically (see the |
Alright, thanks! @srenault ready for review/test on staging |
…y-using-meta-tags
I would really like to have this feature. I think the toolbar is a smart simple solution, but is simply not reliable enough it seems. I often get the wrong or missing documents. Often it simply does not show up at all. |
Types of changes
Overview
Following #94, this PR implements strategy 1 described there. Used documents can be explicitly declared using meta tags to help predictions.
Usage
Declaring the main document
Declaring other documents
Considerations & Limitations
Instead of bypassing the prediction process, I preferred to just make a query and let the prediction process track it. This allows for the prediction API to still resolve prediction-related data that aren't resolvable otherwise (document publication status, abstract, etc.)
This addition only works with public repositories for now.
Try it yourself
Just replace your toolbar script with this one and replace
YOUR_REPO
with yours:Should be working!