TypeError: Cannot read properties of undefined (reading 'undefined')

Hi!
Frontity rookie here. I developed this project last year and it has been working rather smoothly until yesterday or so. It’s hosted on Vercel that says “Internal Server Error” and the function logs tell me “Error: TypeError: Cannot read property ‘undefined’ of undefined”. Running it locally gives me “TypeError: Cannot read properties of undefined (reading ‘undefined’) at LandingPage” and I don’t really know where this is coming from.

My LandingPage looks like this:

import React from "react"
import { connect, styled } from "frontity"

const MainContainer = styled.main``

const LandingPage = ({ state, libraries }) => {
  const data = state.source.get(state.router.link)
  const page = state.source[data.type][data.id]
  const Html2React = libraries.html2react.Component

  return (
    <MainContainer>
      <Html2React html={page.content.rendered} />
    </MainContainer>
  )
}

export default connect(LandingPage)

and it’s being mounted in my TopMain (don’t blame me for the naming) like this:

const TopMain = ({ state }) => {
  const data = state.source.get(state.router.link)
  return (
    <>
      <Switch>
        {data.link === "/" ? (<LandingPage />)
          :
            (<>
              <Header />
              <Main />
              <Footer />
            </>)
        }
      </Switch>
    </>
  )
}

export default connect(TopMain)

When I log the

const data = state.source.get(state.router.link)

I get error 406, so does this mean the issue has to do with fetching from WordPress? Does anyone have a suggestion on how I start debugging this?

Links

System info

System:

  • OS: macOS 11.3
  • CPU: (8) x64 Intel(R) Core™ i5-8257U CPU @ 1.40GHz
  • Memory: 59.80 MB / 16.00 GB
  • Shell: 5.8 - /bin/zsh

Binaries:

  • Node: 16.14.2 - /usr/local/bin/node
  • npm: 8.5.0 - /usr/local/bin/npm

Browsers:

  • Chrome: 100.0.4896.127
  • Edge: 100.0.1185.50
  • Firefox: 99.0.1
  • Safari: 14.1

npmPackages:

  • @aamodtgroup/frontity-contact-form-7: git+https://github.com/HIPPIEKICK/frontity-contact-form-7.git => 0.2.6
  • @daily-co/daily-js: ^0.13.0 => 0.13.0
  • @frontity/core: ^1.13.0 => 1.15.1
  • @frontity/html2react: ^1.6.2 => 1.7.0
  • @frontity/tiny-router: ^1.4.2 => 1.4.4
  • @frontity/wp-source: ^1.11.4 => 1.11.7
  • @orballo/very-tiny-router: ^0.1.2 => 0.1.2
  • dayjs: ^1.10.4 => 1.10.4
  • frontity: 1.15.0 => 1.15.0 (1.17.2)
  • nkjt-theme: file:packages/nkjt-theme => 1.0.0
  • react-router-dom: ^5.2.0 => 5.2.0

npmGlobalPackages:

  • frontity: Not Found
  • npx: Not Found

Hi @matilda! Apparently this endpoint https://api.nkjt.se/wp-json/wp/v2/posts?_embed=true&slug=hem is returning empty, that’s the reason the site is failing.

@orballo Hi there! Thank you for the answer. I’m Matilda’s colleague, and I’m wondering how I can fix this? That endpoint is indeed empty, and not used, so is there any way I can point it differently or to another endpoint? Where can I find these settings?

Thanks in advance!

@karinlinneanordkvist Sorry, I was out on a trip and couldn’t reply earlier. I’m not sure what endpoint should be used to load that content. What endpoint is serving the data you need? Usually Frontity requests posts, and if nothing returned, pages, until it gets some content for the URL slug.

Thanks!

EDIT: Also, did you change something on Frontity or WP before it stopped working?