blitz-js / legacy-framework

MIT License
3 stars 2 forks source link

Prefetch example fails on reading session #161

Closed chrisj-back2work closed 2 years ago

chrisj-back2work commented 2 years ago

What is the problem?

The documentation provides an example of prefetching via invoke: https://blitzjs.com/docs/query-usage#prefetching

I followed that example; my prefetch looks like this: const { someField } = await invoke(getWhatever, { where: {} })

No complaints from eslint or tsc, but when I run the dev server, I get an error message.

Do I need to provide the context / session in some way?

Paste all your error logs here:

Server Error
TypeError: Cannot read properties of undefined (reading 'session')
This error happened while generating the page. Any console logs will be displayed in the terminal window.

Paste all relevant code snippets here:

// the attempted prefetch
const { someField } = await invoke(getWhatever, { where: {} })

What are detailed steps to reproduce this?

  1. import a get___ query
  2. attempt a prefetch via await invoke(getWhatever, { where: {} }) approach
  3. run the dev server
  4. browse to that page

Run blitz -v and paste the output here:

macOS Monterey | darwin-x64 | Node: v16.13.1

blitz: 0.41.1 (local)

  Package manager: yarn
  System:
    OS: macOS 12.0.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 319.88 MB / 32.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 16.13.1 - ~/.asdf/installs/nodejs/16.13.1/bin/node
    Yarn: 1.22.15 - ~/.asdf/installs/yarn/1.22.15/bin/yarn
    npm: 8.1.2 - ~/.asdf/plugins/nodejs/shims/npm
    Watchman: Not Found
  npmPackages:
    @prisma/client: 3.3.0 => 3.3.0
    blitz: 0.41.1 => 0.41.1
    prisma: 3.3.0 => 3.3.0
    react: alpha => 18.0.0-rc.0-next-f2a59df48-20211208
    react-dom: alpha => 18.0.0-rc.0-next-f2a59df48-20211208
    typescript: ~4.3 => 4.3.5

Please include below any other applicable logs and screenshots that show your problem:

No response

beerose commented 2 years ago

Thank you for the report.

beerose commented 2 years ago

Do you have the sessionMiddleware configured in your blitz.config.ts?

beerose commented 2 years ago

Closing due to inactivity.