Skip to content

[WEB-4086] Port Next projects to Vite 4#2491

Merged
jamiehenson merged 1 commit intomainfrom
web-4086-next-to-vite
Apr 3, 2025
Merged

[WEB-4086] Port Next projects to Vite 4#2491
jamiehenson merged 1 commit intomainfrom
web-4086-next-to-vite

Conversation

@jamiehenson
Copy link
Member

@jamiehenson jamiehenson commented Mar 24, 2025

Sandpack is a fussy master.

Unfortunately we can't use Next projects with it, at least with the version of Sandpack we have access to, due to its server-rendering foundations. Thus, it's necessary to rewrite the Next projects to something else that's more clientside, and an obvious candidate for that due to its usage elsewhere here and the general deprecation of create-react-app, is Vite. Though, naturally, Sandpack demands an older version of Vite (4) instead of anything more modern (5, 6).

This PR is a semi-automated rewrite of those projects, and I've also taken the opportunity to further the initial config de-duplication work to make further use of workspaces and reduce the file count down. It also swaps out faker for minifaker, which is objectively inferior but works with Sandpack.

I've tested all of the non-auth react projects locally and they work, with the exception of spaces-live-cursors-javascript which has an ongoing issue not related to this migration. We'll have to hold back on the auth projects and release them with some backend infrastructure in place at a later date.

For @GregHolmes:
Project-wise the general approach I/the bot took was to consolidate the app/page.tsx and app/layout.tsx into one App.tsx component, and replicate multi-page apps with react-router

@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ably-ci ably-ci temporarily deployed to ably-docs-web-4086-next-eysubr March 24, 2025 18:37 Inactive
@jamiehenson jamiehenson force-pushed the web-4086-next-to-vite branch from fc2e338 to 97c2076 Compare March 25, 2025 11:12
@jamiehenson jamiehenson temporarily deployed to ably-docs-web-4086-next-eysubr March 25, 2025 11:12 Inactive
@jamiehenson
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Mar 25, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@jamiehenson jamiehenson force-pushed the web-4086-next-to-vite branch 6 times, most recently from 09ad44b to ca2cede Compare April 1, 2025 11:23
outline: none;
transition: all 0.2s ease-in-out;
}
@import '../../../styles.css';
Copy link
Member Author

Choose a reason for hiding this comment

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

This is an indicator of a change common throughout this PR - project stylesheets have been de-duplicated, with examples/styles.css housing all the common styles, and these ones only importing and adding unique styles.

In the case of no unique styles, the React apps import from examples/styles.css directly. The JS ones have a one line file with an input since index.html can't seem to reach back beyond the directory it's in.

Copy link
Member

Choose a reason for hiding this comment

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

@jamiehenson how will Sandpack handle this? maybe we can include the file and rewrite the import statement while passing it in?

Copy link
Member Author

Choose a reason for hiding this comment

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

@kennethkalmer I've bitten the bullet and brought all the stylesheets back in for the react projects, also relocating them into /src which sandpack more natively expects.

Squashed and cherry picked this into the sandpack branch, it works 👍 (thankfully, the child postcss/vite/tw/ts configs are minimal enough to be handled by sandpack's defaults it seems - so we can maintain a compromise between de-duplication in the repo and stuff that works downstream)

Copy link
Member Author

Choose a reason for hiding this comment

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

One dumb thing I was bashing my head against though is that Sandpack hates Tailwind if it's not brought in as an external script - but that's a downstream change, not for here


export default defineConfig({
...baseConfig,
envDir: '../../',
Copy link
Member Author

Choose a reason for hiding this comment

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

This was a more vite-y approach than dotenv

@@ -0,0 +1,84 @@
import React, { useState, useEffect } from 'react';
Copy link
Member Author

Choose a reason for hiding this comment

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

I wouldn't look too closely at the auth-* projects. They're not in scope to support just yet.

import * as Ably from 'ably';
import { ChatClient, PresenceEvent, PresenceMember, AllFeaturesEnabled } from '@ably/chat';
import { faker } from '@faker-js/faker';
import minifaker from 'minifaker';
Copy link
Member Author

Choose a reason for hiding this comment

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

minifaker was brought in purely because faker blows up sandpack for reasons long and arduous

"react-dom": "^18",
"react-icons": "^5.4.0",
"ts-node": "^10.9.2",
"react-router-dom": "^6.22.2",
Copy link
Member Author

Choose a reason for hiding this comment

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

Brought in react router as the most general example of a routing solution for react, nothing fancy

@jamiehenson jamiehenson force-pushed the web-4086-next-to-vite branch from ca2cede to 5ebff79 Compare April 2, 2025 09:47
Copy link
Member

@kennethkalmer kennethkalmer left a comment

Choose a reason for hiding this comment

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

From my side I think the CSS issue was the only one I spotted so happy to see it is resolved. I think we'll find any other snakes in the grass when packaging them up in sandpack

Excellent conducting @jamiehenson!

@@ -36,3 +36,35 @@ yarn-error.log*
next-env.d.ts

.env.local

Copy link
Member

Choose a reason for hiding this comment

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

Is this file stale?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not fresh. I can search and replace out the next references in the project gitignores

Copy link
Member Author

@jamiehenson jamiehenson Apr 3, 2025

Choose a reason for hiding this comment

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

Hm, even though stale may be better to keep in actually, for the moment. Removing the entries surfaces lots of next stuff that's laying in wait (useless stuff like cache data etc), don't want accidental commits of this stuff elsewhere

@jamiehenson jamiehenson force-pushed the web-4086-next-to-vite branch from 5ebff79 to 9330130 Compare April 3, 2025 10:57
@jamiehenson jamiehenson force-pushed the web-4086-next-to-vite branch from 9330130 to cbd8a8f Compare April 3, 2025 11:11
@jamiehenson jamiehenson merged commit 4447aa8 into main Apr 3, 2025
5 checks passed
@jamiehenson jamiehenson deleted the web-4086-next-to-vite branch April 3, 2025 12:49
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.

4 participants