colbyfayock / next-wordpress-starter

📝 Bring WordPress to the static world with Next.js
https://next-wordpress-starter.spacejelly.dev
MIT License
1.2k stars 292 forks source link

Compiler fails on fresh build when using npm #178

Closed colbyfayock closed 3 years ago

colbyfayock commented 3 years ago

When doing a fresh build using npm instead of yarn, the build fails due to the lack of public/wp-search.json

It seems like npm resolves the files a bit differently and it's not finding it when it hits it

image

colbyfayock commented 3 years ago

some context here - i have ot use npm on the WP Engine Atlas deployment as it doesn't currently support yarn

im wondering if it makes sense just to move the file to a client-side request. i feel like it's been discussed before but kept it as an import

would help reduce the delivered site for bigger sites but of course wouldn't be as speedy

since search is global though, if we load it in the hook immediately when the page loads, it should still appear like it's just as fast as it should load before anyone can try to search something

any thoughts?

GuilleAngulo commented 3 years ago

Couldnt reproduce the error using npm ... I will try again tomorrow just for curiosity

I think that makes sense, once the file is created initializating Fuse on useEffect could work. Just wondering if there is any kind of delay on really big files, could worth making a test?

colbyfayock commented 3 years ago

@GuilleAngulo did you both remove wp-search.json and use npm build?

colbyfayock commented 3 years ago

definitely think its worth making a test. ill put something together to see what itl ooks like

GuilleAngulo commented 3 years ago

Yeah, removed all plugins and installed via npm... maybe i'm missing something

colbyfayock commented 3 years ago

yeah so weird and now all of a sudden im getting the same thing on netlify https://app.netlify.com/sites/next-wordpress-starter/deploys/60b28ac834d35a000760acbf not sure if you can see that

ill put together a POC, wont take long

GuilleAngulo commented 3 years ago

I'm seeing the log...weird.. I kept trying to reproduce, deleting .next, node_modules, wp-search.json and fresh install with npm but im getting no errors... I would say that it seems like something related to jsconfig.json, like is not getting that compiler options where the public folder is resolved... theoretically there is no need of an extra webpack configuration..

colbyfayock commented 3 years ago

thats so strange... not sure. i put together a clientside solution though: https://github.com/colbyfayock/next-wordpress-starter/pull/181

curious if there's a bug beyond that though if you're thinking you see something

colbyfayock commented 3 years ago

@GuilleAngulo im going to merge this in simply because i want to avoid the builds failing, but i'd love to get your feedback on it so i can retroactively make any tweaks if needed

GuilleAngulo commented 3 years ago

hey, sure. I will take a look at it (if not today, will try this week)

GuilleAngulo commented 3 years ago

Hey @colbyfayock , finally I got to take a look, sorry for the delay. Here are some thoughs:

I would like to know your opinion on these thoughts, hope they are helpful =)

colbyfayock commented 3 years ago

Rerenders

From my non-scientific poking around, i think we're safe with rerenders

I put a bunch of console logs on the tree of the homepage:

image

My understanding is that only things that consume it, such as the Navigation, which uses useSearch and ultimately the context, will rerender.

Also https://reactjs.org/docs/context.html#caveats

Thoughts?

Search State

Great idea. Wanna check this out? https://github.com/colbyfayock/next-wordpress-starter/pull/190

getInitialProps

I'd be down to move this back into being read, the build issue is my biggest concern, im not sure if that would still help because my impression was node just wasn't resolving it between the build/compile. you weren't ever able to repro the main issue right?

GuilleAngulo commented 3 years ago

Re-renders: my mistake, you are absolutely right. I usually try to reduce the context at its minimum scope possible, so I ended up thinking it somehow can negatively affect the rest of the tree, but it only affects consumers 👍

Search: I will check the PR and write you there directly 💪

getInitialProps: Yeah I tried but I couldn't reproduce it ... I'll try to search a little more about it, if I can find something. But also the way is now seems totally fine to me, at client-side