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

Update next-transpile-modules, next/link, and next/image for Next.js 13 support #296

Merged
merged 8 commits into from Jan 12, 2023

Conversation

fikrikarim
Copy link
Member

@fikrikarim fikrikarim commented Jan 4, 2023

Resolves PRD-906, PRD-907, PRD-908, PRD-911

Actually, we don't need next-transpile-modules anymore from Next.js v13.1, but we probably need to update it to support v13.0.

So far, I haven't seen any issues from updating next-transpile-modules on Next v12.

@changeset-bot
Copy link

changeset-bot bot commented Jan 4, 2023

🦋 Changeset detected

Latest commit: df110e0

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

This PR includes changesets to release 2 packages
Name Type
@makeswift/runtime Minor
@makeswift/next-plugin Minor

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

@vercel
Copy link

vercel bot commented Jan 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
makeswift-examples-basic-typescript ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 12, 2023 at 5:29PM (UTC)
makeswift-examples-bigcommerce ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 12, 2023 at 5:29PM (UTC)
makeswift-examples-react-countup ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 12, 2023 at 5:29PM (UTC)
makeswift-examples-shopify ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 12, 2023 at 5:29PM (UTC)
makeswift-examples-thirdweb ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 12, 2023 at 5:29PM (UTC)

Copy link
Member

@migueloller migueloller left a comment

Choose a reason for hiding this comment

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

These changes look good, but I don't think we can ship them as-is since it would likely break users in Next.js v12, right? For example, the useLegacyBehavior prop is only in next/link when using Next.js v13?

I think that the way that we handle support for Next.js v13 is similar to how React introduced the useSyncExternalStore for React 18. They released a package use-sync-external-store, and that package had a shim use-sync-external-store/shim. A shim is a module that will transparently use the native library if it's available and otherwise it provides an appropriate replacement. In the case of useSyncExternalStore, if you're on React v18 is just uses the one from React, otherwise it falls back to a close implementation for React < v17.

https://github.com/facebook/react/blob/de7d1c90718ea8f4844a2219991f7115ef2bd2c5/packages/use-sync-external-store/src/useSyncExternalStoreShim.js#L21

We don't need to make a separate package, but we can create shim modules for Next.js features so that we can ship the same behavior across different versions of Next.js (e.g., next-transpile-modules, new next/image, and new next/link).

@linear
Copy link

linear bot commented Jan 6, 2023

PRD-908 Update Image component for Next.js v13

Progress:

Seeing a weird hydration issue when using next/legacy/image, but it's only on some images:

image.png

@fikrikarim fikrikarim changed the title Update next-transpile-modules and next/link for Next.js 13 support Update next-transpile-modules, next/link, and next/image for Next.js 13 support Jan 6, 2023
Copy link
Member

@migueloller migueloller left a comment

Choose a reason for hiding this comment

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

Maybe instead of vendoring the SemVer utilities we can add the semver package as a dependency?

packages/makeswift-next-plugin/index.js Outdated Show resolved Hide resolved
packages/runtime/src/runtimes/react/index.tsx Outdated Show resolved Hide resolved
Copy link
Member

@migueloller migueloller left a comment

Choose a reason for hiding this comment

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

  • Should we also update Next.js, React, etc. in the peer dependencies of the package.json for that first commit?
  • Any reason why we don't have a changeset for each commit? It's ok not to have one for each commit, but we should make sure that the final changelog has a very clear explanation of what changed, why, and how it will impact a user if they upgrade as well as migration instructions if relevant

packages/runtime/src/state/react-builder-preview.ts Outdated Show resolved Hide resolved
packages/runtime/src/next/api-handler.ts Show resolved Hide resolved
packages/runtime/src/components/builtin/Image/Image.tsx Outdated Show resolved Hide resolved
packages/runtime/src/components/builtin/Image/Image.tsx Outdated Show resolved Hide resolved
packages/runtime/src/next/nextVersion.ts Outdated Show resolved Hide resolved
packages/runtime/src/state/react-builder-preview.ts Outdated Show resolved Hide resolved
@fikrikarim
Copy link
Member Author

  • Should we also update Next.js, React, etc. in the peer dependencies of the package.json for that first commit?

I think we should update the peer dependencies on the last commit, as we need all the previous commits before we can support the Next.js v13.

  • Any reason why we don't have a changeset for each commit? It's ok not to have one for each commit, but we should make sure that the final changelog has a very clear explanation of what changed, why, and how it will impact a user if they upgrade as well as migration instructions if relevant

Yeah, I don't think we need a changeset for a refactor or anything that doesn't change the external behavior. Yes, I agree, let's do the final changelog together.

packages/runtime/src/next/next-version.ts Outdated Show resolved Hide resolved
packages/runtime/src/state/react-builder-preview.ts Outdated Show resolved Hide resolved
We had error "Error: This Suspense boundary received an update
before it finished hydrating." when upgrading to Next.js v13.

This was because we were calling setStore before the page finished
hydrating. We fix this by splitting the RuntimeProvider to two
different providers: PreviewProvider, and LiveProvider.

So instead of using an useEffect to rerender the correct provider,
we check for the preview prop passed from the snapshot.
We don't support Next.js below version 12.2 anymore,
so it's safe to remove unstable_revalidate.
Somehow after commit "d9725fc refactor: split the RuntimeProvider",
texts are not editable on the builder.
@fikrikarim fikrikarim merged commit d70c32b into main Jan 12, 2023
@fikrikarim fikrikarim deleted the fikri/next13 branch January 12, 2023 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants