Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App Directory: Uncaught Error: DYNAMIC_SERVER_USAGE with NextJS 13.5.4, BlitzJS 2.0.0-beta.34 #4232

Closed
tordans opened this issue Oct 12, 2023 · 6 comments · Fixed by #4318
Closed
Assignees
Labels
kind/bug Something isn't working status/done
Projects

Comments

@tordans
Copy link
Contributor

tordans commented Oct 12, 2023

What is the problem?

I created a fresh blitz app, added a project model with some user relation and migrated it to the app directory.

The app now shows the error message

Unhandled Runtime Error
Error: DYNAMIC_SERVER_USAGE

Call Stack
updateDehydratedSuspenseComponent
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (16385:0)
updateSuspenseComponent
node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js (16081:0)

image

Ping #4112 and #4149 but this is based on the newest blitz and next js versions.

Paste all your error logs here:

Demo app is here https://github.com/FixMyBerlin/blitz-test

Paste all relevant code snippets here:

What are detailed steps to reproduce this?

  1. Run the demo https://github.com/FixMyBerlin/blitz-test
  2. Create a user
  3. Create a project
  4. Open http://localhost:3000/users/1/projects, which is where I see the error first

Run blitz -v and paste the output here:

% blitz -v
Blitz version: 2.0.0-beta.33 (global)
Blitz version: 2.0.0-beta.34 (local)
macOS Ventura | darwin-arm64 | Node: v18.8.0


 Package manager: npm

  System:
    OS: macOS 13.6
    CPU: (8) arm64 Apple M1
    Memory: 40.78 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.8.0 - ~/.nvm/versions/node/v18.8.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.8.0/bin/yarn
    npm: 9.8.0 - ~/.nvm/versions/node/v18.8.0/bin/npm
  npmPackages:
    @blitzjs/auth: 2.0.0-beta.34 => 2.0.0-beta.34
    @blitzjs/next: 2.0.0-beta.34 => 2.0.0-beta.34
    @blitzjs/rpc: 2.0.0-beta.34 => 2.0.0-beta.34
    @prisma/client: 5.4.2 => 5.4.2
    blitz: 2.0.0-beta.34 => 2.0.0-beta.34
    next: 13.5.4 => 13.5.4
    prisma: 5.4.2 => 5.4.2
    react: 18.2.0 => 18.2.0
    react-dom: 18.2.0 => 18.2.0
    typescript: ^5.2.2 => 5.2.2

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

No response

@tordans tordans added kind/bug Something isn't working status/triage labels Oct 12, 2023
@tordans tordans changed the title Uncaught Error: DYNAMIC_SERVER_USAGE at updateDehydratedSuspenseComponent App Directory: Uncaught Error: DYNAMIC_SERVER_USAGE at updateDehydratedSuspenseComponent with NextJS 13.5.4, BlitzJS 2.0.0-beta.34 Oct 12, 2023
@tordans tordans changed the title App Directory: Uncaught Error: DYNAMIC_SERVER_USAGE at updateDehydratedSuspenseComponent with NextJS 13.5.4, BlitzJS 2.0.0-beta.34 App Directory: Uncaught Error: DYNAMIC_SERVER_USAGE with NextJS 13.5.4, BlitzJS 2.0.0-beta.34 Oct 12, 2023
@NoahJinnn
Copy link

NoahJinnn commented Oct 13, 2023

I also faced this issue while doing server-side rendering, I noticed that when I'm able to access my page by going from "/" to "/dashboard" BUT can not access "/dashboard" directly. In my component, I want to use useQuery to render my component. (dateString props is passed by dynamic page rendering)

// Dashboard.jsx
const Calendar = ({ dateString }: { dateString?: string | undefined }) => {
  let currentDate: Date = new Date();
  if (dateString) {
    currentDate = convertDateStringToDate(dateString);
  }
  const [scheduledClasses] = useQuery(getClasses, {
    dateString,
  });
  
  // ...other code
 return ( // .... )
}

The error won't appear if I removed useQuery but it is not what I want. I temporarily fixed this by forcing the code to use client-side rendering with this trick:

// DashboardLayout.jsx
const [render, setRender] = useState(false);
  useEffect(() => {
    setRender(true);
  }, []);
// ...
<AppShell.Main>{render && children}</AppShell.Main>

tordans added a commit to FixMyBerlin/blitz-test that referenced this issue Oct 13, 2023
@tordans
Copy link
Contributor Author

tordans commented Oct 13, 2023

by forcing the code to use client-side rendering

I have 'use client' in every file in the app directory + blitz-client. This seems to be needed, since BlitzProvider is a client component (I just opened blitz-js/blitzjs.com#847 to clarify this in the docs).

My understanding is, that the use client directive makes it a client component.

I temporarily fixed this by forcing the code to use client-side rendering with this trick…

I tried your setRender workaround in FixMyBerlin/blitz-test@e31eeed but that has no effect on the error:

image

And adding it to the layout as well causes new hydration errors.

@tordans
Copy link
Contributor Author

tordans commented Oct 25, 2023

It looks like this error came from a library that we used 'osm-auth'. Once I remove it, the error is gone. I will close this here and referenced it at osmlab/osm-auth#124.

@tordans tordans closed this as completed Oct 25, 2023
@blitzjs-bot blitzjs-bot added this to Done in Toolkit Oct 25, 2023
@tordans tordans reopened this Oct 30, 2023
Toolkit automation moved this from Done to In progress Oct 30, 2023
@tordans
Copy link
Contributor Author

tordans commented Oct 30, 2023

@siddhsuresh FYI I reopened this ticket. We managed to somehow get rid of the error in our main flow which is why I thought it was related to the library I mentioned but that was wrong and I could have know because the demo app that this bug report is based on (https://github.com/FixMyBerlin/blitz-test) shows the error without without any special dependencies.

@siddhsuresh siddhsuresh added status/ready-to-work-on This issue is up for grabs and removed status/done labels Oct 30, 2023
@siddhsuresh
Copy link
Member

Thanks for the update @tordans I will take a look in some time.

@timeemit
Copy link

Ran into this issue while migrating a Blitz app from pages router to app router. Managed to isolate the issue to useQuery.
@NoahJinnn's fix of forcing the page to render client side with the useEffect() hook worked for me.

@siddhsuresh siddhsuresh self-assigned this Mar 6, 2024
@blitzjs-bot blitzjs-bot added status/assigned and removed status/ready-to-work-on This issue is up for grabs labels Mar 6, 2024
@kodiakhq kodiakhq bot closed this as completed in #4318 Apr 2, 2024
Toolkit automation moved this from In progress to Done Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working status/done
Projects
Development

Successfully merging a pull request may close this issue.

5 participants