CrustyRatFink
CrustyRatFink

Reputation: 534

Next.js SSG page not attaching events or running Javascript when accessed directly

I've got a next.js (11) site that generates a bunch of SSG pages. Everything works great when I enter the site through the homepage, which is static and navigate to the SSG page.

BUT, if I go directly to the SSG page, nothing works. Javascript doesn't run. Events aren't attached. No errors. Just... dead except for the static content.

Am I missing something about how Next.js works here? Is there a way to force these pages to function when accessed directly?

The site is running on Netlify. All of this works locally but not in production.

Upvotes: 1

Views: 512

Answers (1)

CrustyRatFink
CrustyRatFink

Reputation: 534

The answer for posterity is that there's no reason it should act this way. It's a bug that results from minifying the Javascript on Netlify. Once I turned that off, everything behaved as expected.

Things I tried:

  • SSR instead of SSG... but that breaks Netlify redirects and is slower.
  • I also tried a trick I saw suggested to do a useEffect to set some unused key in state and force a rerender, but because Javascript was garfed, that didn't even fire.
  • Dynamic loading of modules. Also didn't work right with the minification in place.
  • Updates of all of my component modules-- including Next and the Netlify Next plugin.

Then, just by chance and desperation, I clicked off the post-processing minification button and everything started working again.

Upvotes: 2

Related Questions