Skip to content

Next.js Tutorial #142

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

Merged
merged 6 commits into from
Apr 4, 2025
Merged

Next.js Tutorial #142

merged 6 commits into from
Apr 4, 2025

Conversation

michaelbarnes
Copy link
Contributor

This PR introduces a new "from scratch" tutorial on how to create a Next.js app that integrates with PowerSync. This is WIP and needs more polish.

@michaelbarnes michaelbarnes changed the title WIP: Next.js Tutorial Next.js Tutorial Mar 26, 2025
@michaelbarnes michaelbarnes requested a review from Chriztiaan April 1, 2025 20:53

### Install PowerSync Dependencies

Using PowerSync in a Next.js application will require the use of the [PowerSync Web SDK](https://www.npmjs.com/package/@powersync/web) and it's peer dependencies.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Using PowerSync in a Next.js application will require the use of the [PowerSync Web SDK](https://www.npmjs.com/package/@powersync/web) and it's peer dependencies.
Using PowerSync in a Next.js application will require the use of the [PowerSync Web SDK](https://www.npmjs.com/package/@powersync/web) and its peer dependencies.


We also instantiate our `BackendConnector` and pass an instance of that to `db.connect()`. This will connect to the PowerSync instance, validate the token supplied in the `fetchCredentials` function and then start syncing with the PowerSync service.

#### DynamicSystemProvider.tsx
Copy link
Contributor

Choose a reason for hiding this comment

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

This section is very much the crux of using Next+PS. It would be useful to address this solution in the context of how many Next apps will be structured. Say they have a home, about, a login, and dashboard page - with the dashboard being available after login and the only section that depends on PS. So in that scenario this snippet only opts out of SSR for the dashboard page (or a subsection), this is great because it means they should still be able to have full SSR for the other pages which affects things like SEO and initial page load performance.

I am not sure if whether it's more relevant to this tutorial or a more general entry for Next.

Copy link
Contributor Author

@michaelbarnes michaelbarnes Apr 3, 2025

Choose a reason for hiding this comment

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

Okay, maybe we should add a note in the intro which could read like this:

At present PowerSync will not work with SSR enabled with Next.js and in this guide we disable SSR across the entire app. However, it is possible to have other pages, which do not require authentication for example, to still be rendered server-side. This can be done by only using the DynamicSystemProvider (covered further down in the guide) for specific pages. This means you can still have full SSR on other page which do not require PowerSync.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect 👌

@Chriztiaan
Copy link
Contributor

Beyond minor polish, LG2M - was easy to follow :)

@michaelbarnes michaelbarnes merged commit 76389b5 into docs Apr 4, 2025
3 checks passed
@michaelbarnes michaelbarnes deleted the guide/next.js branch April 4, 2025 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants