newrelic / developer-website

Source code for the New Relic Developer Site.
https://developer.newrelic.com
Apache License 2.0
40 stars 114 forks source link

[Public Catalog] Gatsby 4 + SSR exploration #1821

Closed jpvajda closed 3 years ago

jpvajda commented 3 years ago

To prepare for possible integration with the DevEx sort / popularity service we want to test out gatsby 4 with support for SSR to validate this approach is viable.

Assumption

The I/O external site would be able to use this DevEx service to power our sort and popularity functionality instead of rebuilding that ourselves on the external site. This would then allow us to only rely on 1 single service to provide that both the internal and external I/O catalogs.

Acceptance Criteria

This exploration is just for the DevSite

Gameday considerations

a. sort /popularity service is down b. gatsby functions are down, which support SSR c. other

Docs

Some takeaways

aswanson-nr commented 3 years ago

The build is currently running into some issues during the "Validating Rendering Engines" step. I believe it may have something to do with the mockGlobals file in our SDK plugin, but I haven't been able to prove that yet.

Screen Shot 2021-11-09 at 4 25 02 PM
aswanson-nr commented 3 years ago

The error above was generated when doing a full yarn build of the site. I was able to render the test page on another Gatsby site that I created to test this with, so the issue is definitely within the dev site.

aswanson-nr commented 3 years ago

Removing the test-ssr page and keeping gatsby 4, caused a different error:

Screen Shot 2021-11-10 at 5 15 13 PM

I'm not sure if this is caused by theme plugins or code within the developer repo.

aswanson-nr commented 3 years ago

I also tested changing the globalMocks file in the sdk plugin to not override the global object and that did not work. However, removing the plugin completely does allow the site to build. So, the issue appears to be around the gatsby-source-newrelic-sdk plugin and the upgrade to Gatsby 4.

roadlittledawn commented 3 years ago

Re: gatsby v4 ssr. Here's what I did to try and read the new relic api key from node env vars. initially didn't work, but then @nr-kkenney changed the NEW_RELIC_API_KEY in the GC Site Settings to prepend GATSBY_ that's being referenced in the test-ssr.js file and it works.

not 100% sure why though. i tested initially using the same env var names and got same error re: no api key. ¯_(ツ)_/¯

https://github.com/newrelic/developer-website/compare/802747f...d89b14a

Gatsby doc on env vars: https://www.gatsbyjs.com/docs/how-to/local-development/environment-variables/

moonlight-komorebi commented 3 years ago

we were able to get our test page to work. we also added the ability to supply an id as a query param, and for that quickstart to be fetched and displayed.

for example: https://developerwebsitecampfiretestv4.gatsbyjs.io/test-ssr/?id=29bd9a4a-1c19-4219-9694-0942f6411ce7 and if you remove the id, you just see the initial page.

this should mean its possible for us to proceed with our upcoming work.

jpvajda commented 3 years ago

This is awesome! I'm curious will this SSR implementation have any impacts to tessen events or analytics we should be aware of? 🤔

roadlittledawn commented 3 years ago

@jpvajda for now, tessen events fired as expected. depending on implementation down the road (e.g., if a quickstart page URL uses query params to fetch quickstart by id), we may want to tweak the tessen properties so there's enough data in the event to tell what quickstart the page contains, etc.