add support for disabling adapters (#38542) #38549
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Add support for disabling adapters to work around the issues described in #38542.
Zero-configuration deployments and adapters are a great step forward for Gatsby and looking forward to seeing them expand. In the meantime, hopeful that you will consider this PR that helps address two primary demographics:
Documentation
Updates to docs exist in the PR, if I missed any places that should be updated and/or if the changes made need adjusting, please just let me know, happy to make any changes.
Note - On zero configuration deployments, I removed the first paragraph since it seemed duplicative with the third paragraph.
Tests
Added unit tests and verified with
yarn test
,yarn jest packages/gatsby/src/joi-schemas
,yarn jest packages/gatsby/src/utils/adapter
andyarn jest packages/gatsby/src/redux
.Note - When I run
yarn test
, some tests, outside of the ones I changed/added, are failing. Not sure if this is a local machine issue (possibly I didn't setup correctly) or if the tests are really failing. The 9 failing tests are:Related Issues
Issues: #38542, #38541, #33555
Discussions: #38527, #38528
Additional Information
Approach
There were four ways that I felt providing support for disabling adapters could be achieved:
noOpAdapter
adapter that can be configured viaadapter
configurationI decided to go with the first option as it seemed the most explicit (no hidden environment variables) and most straightforward. If the preference is to take a different route with providing support for this (either via one of the other options or another one entirely), please just let me know and I can make the change.
Other issues/questions
While making this change, I noticed two different other potential issues in the same code-path. I did not make any changes to either of these as my goal was to provide support for disabling adapters and keep the changes as small as possible (only 1 line of code in the runtime changed in this PR), however if you feel these changes are warranted, I can make them and/or create new issues to track them.
true
, a non-empty string, etc.), it will head down the path of a configured adapter but the value from config may not be an object and it may not includeadapt
method. As it stands, this will result in no adapter being used, no warning emitted to user, etc. but internally, the runtime will believe there is an adapter and all code from that point assumes adapter is an object. Suggestions here are to validate thatadapterFromGatsbyConfig
is an object andadapt
is present (to match the schema validation) and if not, either fail or go down thenoOpAdapterManager
route.adapt
function, according to IAdapter is required, however if it's not present, the adapt phase will just be skipped without any warning/error emitted to user which could lead to unexpected outcomes. Suggest either requiringadapt
as the type defines or at least emitting a warning.When adapters are explicity disabled, there may be value in having the telemetry be a different value for when trackFeatureIsUsed (e.g.,
adapter:no-op:disabled
). Also, could update the currentadapter:no-op
to beadapter:no-op:not-found
) so the different reasons for using thenoOpAdapterManager
can be identified. If updates to any of these are desired, please just let me know, happy to update.When updating the joi tests, I noticed that simply checking
result.value?.<propertyname>
for the expected configuration does not appear to be enough to confirm there was no error as it seems thatresult.value?.<propertyname>
always contains the full input even if it was invalid (seems to contradict the joi docs that indicate value will bethe validated and normalized value
). Given this, I included an assert to ensure there were no errors. Possibly I am making a mistake but if my understanding is correct, it might be advisable to update the other joipositive
test scenarios to assert on error property and ensure itstoBeNil()
.In the manually installing the adapter docs, it mentions that if you'll be on a supported platform for a while, there are benefits to manual configuration. Another benefit not mentioned is that manual configuration will ensure your builds always use the adapter vs. sometimes. For example, when running
gatsby build
locally, thegatsby-adapter-netlify
adapter will not be used (unless manually configured) because !!process.env.NETLIFY || !!process.env.NETLIFY_LOCAL will evaluate to false (unless it's been added to the environment by the user). Having the build always use the adapter, even when local, ensures consistency with the builds on the target platform. There is something to be said for not having the adapter used on everygatsby build
locally but I do think its worth mentioning that to mirror the behavior locally,netlify cli
should be used so at least the user knows there will be a difference. Additionally, as more adapters are introduced, thetest
could differ to when/how adapters are automatically configured. I didn't add anything related to any of this in to the docs as I wasn't sure if it was intentionally left out but if desired, I can add a mention of this based on your guide on what to add.