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

Handle isbot v4 in a backwards-compatible manner #8415

Merged
merged 4 commits into from
Jan 3, 2024

Conversation

brophdawg11
Copy link
Contributor

@brophdawg11 brophdawg11 commented Jan 2, 2024

Background:

  • Remix apps need isbot installed for use by the default provided entry.server.tsx (and the one internally used by remix dev if one is not present in the app)
  • remix dev adds isbot to package.json if it does not exist but it does so with the latest tag
  • isbot released v4 on 1/1/2024 and moved from a default to a named export
  • Any Remix apps that did a fresh install post-1/1/2024 that got the latest v4 version ran into build/runtime issues since their entry.server (or the internal one) assumed a default export which no longer existed
    • This should only be a problem for fresh installs that re-evaluate latest - it should not be an issue AFAIK for apps using lockfiles since those should have the v3 version pinned internally
  • The fix for those apps is to just downgrade isbot from latest to ^3 in their package.json

Solution

  • Moving forward, we'll use isbot v4 and remix dev will update package.json with "isbot": "^4" instead of latest
  • However, the internal templates used by remix dev can't assume v4 since there are Remix apps in the wild that may have "isbot": "3.x.y" in their package.json (if they changed it from latest) that are using the internal entry.server.tsx file.
  • So, we need our internal remix dev defaults to handle both isbot v3 or v4
  • Templates are updated to v4 so any net-new apps moving forward will install v4, and the entry.server.tsx in templates will assume v4 for net new apps

Reimplements #8385 which was reverted in #8414
Closes #8407, #8392

Copy link

changeset-bot bot commented Jan 2, 2024

🦋 Changeset detected

Latest commit: 821f914

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@remix-run/dev Patch
create-remix Patch
remix Patch
@remix-run/architect Patch
@remix-run/cloudflare Patch
@remix-run/cloudflare-pages Patch
@remix-run/cloudflare-workers Patch
@remix-run/css-bundle Patch
@remix-run/deno Patch
@remix-run/eslint-config Patch
@remix-run/express Patch
@remix-run/node Patch
@remix-run/react Patch
@remix-run/serve Patch
@remix-run/server-runtime Patch
@remix-run/testing Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

templates/arc/app/entry.server.tsx Outdated Show resolved Hide resolved
@@ -66,7 +66,7 @@ export default function handleRequest(
remixContext: EntryContext,
loadContext: AppLoadContext
) {
return isbot(request.headers.get("user-agent"))
return isbot(request.headers.get("user-agent") || "")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All docs are updated to reflect the v4 API

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This use case is supported as is starting [email protected]

Suggested change
return isbot(request.headers.get("user-agent") || "")
return isbot(request.headers.get("user-agent"))

@@ -997,7 +997,7 @@ test.describe("aborted", () => {
remixContext: EntryContext,
loadContext: AppLoadContext
) {
return isbot(request.headers.get("user-agent"))
return isbot(request.headers.get("user-agent") || "")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All internal unit/e2e tests and the repo itself are updated to use v4

@@ -493,7 +493,7 @@ export async function resolveConfig(
pkgJson.update({
dependencies: {
...pkgJson.content.dependencies,
isbot: "latest",
isbot: "^4",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going forward, remix dev will add v4 to the package.json instead of latest - this is the primary "fix"

@@ -22,7 +22,7 @@ export default async function handleRequest(
}
);

if (isbot(request.headers.get("user-agent"))) {
if (isBotRequest(request.headers.get("user-agent"))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal implementations of entry.server.tsx will support either v3 or v4 for backward compatibility with existing Remix apps who have pinned v3 in their package.json

@@ -24,7 +24,7 @@ export default function handleRequest(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
loadContext: AppLoadContext
) {
return isbot(request.headers.get("user-agent"))
return isbot(request.headers.get("user-agent") || "")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Templates use v4 API moving forward

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use case has been addressed with version 4.2.0 to accept "null" as input, with the intention to keep user code cleaner.

https://github.com/omrilotan/isbot/blob/main/CHANGELOG.md#420

Accept null in place of user agent string to allow header value to be used "as is" (request.headers.get("user-agent"))

@brophdawg11 brophdawg11 merged commit 131bcca into dev Jan 3, 2024
9 checks passed
@brophdawg11 brophdawg11 deleted the brophdawg11/isbot-4 branch January 3, 2024 19:26
@github-actions github-actions bot added the awaiting release This issue has been fixed and will be released soon label Jan 3, 2024
Copy link
Contributor

github-actions bot commented Jan 9, 2024

🤖 Hello there,

We just published version 2.5.0-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

🤖 Hello there,

We just published version 2.5.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@github-actions github-actions bot removed the awaiting release This issue has been fixed and will be released soon label Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants