Skip to content

[Cloudflare Pages] Custom component mark 500 error: cannot read properties of null (reading 'ce') #71

Open
@davidstackio

Description

@davidstackio

When I deploy the following to Cloudflare Pages I get the 500 error cannot read properties of null (reading 'ce') during SRR. I'm using Nuxt.

SanityLink.vue

<script setup lang="ts">
// Props
const props = defineProps<{
  href?: string;
}>();
</script>

<template>
  <NuxtLink :to="href">
    <slot />
  </NuxtLink>
</template>

SanityRichText.vue

<script setup lang="ts">
// Types
import type { PortableTextBlock } from "@portabletext/types";
import type { PortableTextMarkComponentProps } from "@portabletext/vue";

import { PortableText } from "@portabletext/vue";

// Explicit component imports
import LazySanityLink from "./SanityLink.vue";

// Props
defineProps({
  content: {
    type: Array<PortableTextBlock>,
    required: true,
  },
});

// Custom components
const components = {
  marks: {
    link: (props: PortableTextMarkComponentProps, { slots }: any) => {
      return h(
        // Pass the component
        LazySanityLink,
        // Pass individual props
        { href: props.value?.href },
        // Pass children slots
        slots
      );
    },
  },
};
</script>

<template>
  <div>
    <PortableText :value="content" :components />
  </div>
</template>

Here's what I know from my troubleshooting:

  1. The issue occurs on Cloudflare Pages during SSR/hydration. It works fine during client side navigation and locally during dev.
  2. It's specific to a SanityLink.vue when it renders dynamic content via <slot />.
  3. Hardcoding 'test' inside the SanityLink.vue instead of using <slot /> works.
  4. Wrapping the <slot /> in <ClientOnly> inside SanityLink.vue works.
  5. Using SanityLink instead of LazySanityLink doesn't make a difference.

Other causes of this error include mismatched Vue versions which I've already checked for. I've already spent many hours on this.

On a related note, when I use slots.default?.() instead of slots in my SanityRichText.vue component (as per the docs, I get a Vue console error: [Vue warn]: Non-function value encountered for default slot. Prefer function slots for better performance. .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions