Skip to content

Commit

Permalink
Merge pull request #1475 from prismicio/dani/snippets
Browse files Browse the repository at this point in the history
Refetch field snippet when field config changes
  • Loading branch information
dani-mp authored Nov 5, 2024
2 parents a80b6d6 + 3c6fc43 commit b8eb04e
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ const Hint: React.FC<HintProps> = ({
}) => {
const fieldPathString = renderHintBase({ item });

// TODO: Call `swr`'s global `mutate` function when something changes to clear the cache.
const snippetCacheKey = [fieldPathString];
if (item.value.type === "Link") {
if (item.value.config?.allowText ?? false)
snippetCacheKey.push("allowText");
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { data, error } = useSWR(fieldPathString, async () => {
const { data, error } = useSWR(snippetCacheKey.join("$"), async () => {
return await managerClient.snippets.readSnippets({
fieldPath: fieldPathString.split("."),
model: item.value,
Expand Down

0 comments on commit b8eb04e

Please sign in to comment.