question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Preview not working properly after upgrade to 2.1.5

See original GitHub issue

Describe the bug

Previews using a react component returns undefined after upgrading from the following packages:

@sanity/base               2.1.2 → 2.1.5
@sanity/components         2.1.0 → 2.1.4
@sanity/core               2.1.2 → 2.1.4
@sanity/default-layout     2.1.3 → 2.1.5
@sanity/default-login      2.1.0 → 2.1.4
@sanity/desk-tool          2.1.3 → 2.1.5
@sanity/google-maps-input  2.1.3 → 2.1.5
@sanity/vision             2.1.0 → 2.1.4

To Reproduce

Steps to reproduce the behavior:

  1. Create a fresh project using the cli.
  2. Add the following to your schemas/schema.js.
// First, we must import the schema creator
import createSchema from "part:@sanity/base/schema-creator";

// Then import schema types from any plugins that might expose them
import schemaTypes from "all:part:@sanity/base/schema-type";

const supportedLanguages = [
  { id: "en", title: "English", isDefault: true },
  { id: "da", title: "Danish" },
  { id: "nb", title: "Norwegian" },
  { id: "sv", title: "Swedish" },
];

// Then we give our schema to the builder and provide the result to Sanity
export default createSchema({
  // We name our schema
  name: "default",
  // Then proceed to concatenate our document type
  // to the ones provided by any plugins that are installed
  types: schemaTypes.concat([
    {
      name: "localeString",
      type: "object",
      fieldsets: [
        {
          title: "Translations",
          name: "translations",
          options: { collapsible: true },
        },
      ],
      fields: [
        {
          name: "key",
          title: "Key",
          type: "string",
          validation: (Rule) =>
            Rule.lowercase().warning("All lower case for a key is prefered"),
        },
        ...supportedLanguages.map((lang) => ({
          title: lang.title,
          name: lang.id,
          type: "string",
          fieldset: lang.isDefault ? null : "translations",
        })),
      ],
      preview: {
        select: {
          title: "key",
          ...supportedLanguages.reduce(
            (acc, cur) => ({ ...acc, [cur.id]: cur.id }),
            {}
          ),
        },
        prepare: ({ title, ...lngs }) => {
          const missingLngs = Object.entries(lngs)
            .filter((lng) => !lng[1])
            .map((lng) => lng[0]);
          return {
            title: `${title} - ${lngs.en}`,
            subtitle:
              missingLngs.length > 0
                ? `Missing: ${missingLngs.join(", ")}`
                : "Everything present",
            media: <span>{missingLngs.length > 0 ? "🚨" : "✔️"}</span>,
          };
        },
      },
    },
    {
      title: "Translations",
      name: "namespaces",
      type: "document",
      fields: [
        {
          name: "namespace",
          title: "Namespace",
          type: "string",
          validation: (Rule) => Rule.required().lowercase(),
        },
        {
          title: "translations",
          name: "translations",
          type: "array",
          of: [{ type: "localeString" }],
          validation: (Rule) =>
            Rule.unique().error(
              "Should not have a duplicate translation in the same namespace"
            ),
        },
      ],
    },
  ]),
});

  1. Start studio and create a translation document. Add a value to the namespace field and add a new translation to the translation array.
  2. See that array field is returned as undefined instead of specified component.

Expected behavior Expected too see an array element with ✔️ or 🚨 along with a title and subtitle, as seen in the screenshot. Instead I get undefined and no icon. This worked on previous versions mentioned above.

Screenshots Expected behaviour image

Error behaviour image

Which versions of Sanity are you using?

Run sanity versions in the terminal and copy-paste the result here.

@sanity/cli             1.149.16 (latest: 2.1.4)
@sanity/base               2.1.5 (up to date)
@sanity/components         2.1.4 (up to date)
@sanity/core               2.1.4 (up to date)
@sanity/default-layout     2.1.5 (up to date)
@sanity/default-login      2.1.4 (up to date)
@sanity/desk-tool          2.1.5 (up to date)
@sanity/vision             2.1.4 (up to date)

What operating system are you using? wsl2 ubuntu

Which versions of Node.js / npm are you running?

6.14.5
v14.4.0

Additional context

Security issue? No

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Bjodolcommented, Jan 14, 2021

Thanks @bjoerge - Look fine here as well 👍

1reaction
Aratrambacommented, Jan 14, 2021

thanks @bjoerge - works fine now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's new in the updates for macOS Big Sur? - Apple Support
macOS Big Sur 11.6.7 fixes an issue where Mail and other apps, such as Microsoft Outlook, can't open attachments if the app required...
Read more >
[Update] T4 Framework 2.1.5: improvements and multiple bug ...
Hi guys,. T4 Framework 2.1.5 is here. This new version is updated for improvements and multiple bug fixes:.
Read more >
What is the migration guidelines to migrate .NET Core 2.1 ...
Hello! I'm looking for some guidance on migrating .NET Core 2.1 applications to .NET 6(Preview). As .NET 6 is going to be a...
Read more >
Mac Release Notes - Your Journal for Life | Day One
A few bug fixes that needed to be addressed earlier than our usual release schedule. 6.9.2 (September 21, 2021). Fixed an issue with...
Read more >
Help Center BIAS FX 2 Desktop Update History / Release Notes
BIAS FX 2 Desktop Update History / Release Notes · Minor bugs fixes and performance improvements. · Fixed "No guitar match profile available...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found