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

feature: Realtime setup and generator commands out of experimental and into main cli #9342

Merged

Conversation

dthyresson
Copy link
Contributor

@dthyresson dthyresson commented Oct 26, 2023

This PR moves the RedwoodJS Realtime cli (setup and generators) out of the experimental cli and into the main cli.

Note that these still require the "experimental server file" to be setup and we'll refactor this rule once @jtoar and @Josh-Walker-GM complete the rework on server file.

  • If Server not setup, then setup automatically
  • Documentation

Examples:

Setup

rt-setup-test % yarn rw setup realtime
✔ Checking for realtime environment prerequisites ...
✔ Adding required api packages...
✔ Adding the realtime api lib ...
✔ Adding Countdown example subscription ...
✔ Adding NewMessage example subscription ...
✔ Adding Auctions example live query ...
✔ Generating types ...

Note: You may need to manually restart GraphQL in VSCode to see the new types take effect.
rt-setup-test % 

Generators

rt-setup-test % yarn rw g realtime NewLiveQuery
? What type of realtime event would you like to create? › - Use arrow-keys. Return to submit.
❯   Live Query
    Create a Live Query to watch for changes in data
    Subscription

✔ What type of realtime event would you like to create? › Live Query
✔ Checking for realtime environment prerequisites ...
✔ Adding newlivequery example live query ...
✔ Generating types ...

Note: You may need to manually restart GraphQL in VSCode to see the new types take effect.
rt-setup-test % 

and

rt-setup-test % yarn rw g realtime NewSub      
? What type of realtime event would you like to create? › - Use arrow-keys. Return to submit.
    Live Query
❯   Subscription - Create a Subscription to watch for events

✔ What type of realtime event would you like to create? › Subscription
✔ Checking for realtime environment prerequisites ...
✔ Adding newsub example subscription ...
✔ Generating types ...

Note: You may need to manually restart GraphQL in VSCode to see the new types take effect.
rt-setup-test % 

@dthyresson dthyresson added the release:feature This PR introduces a new feature label Oct 26, 2023
@dthyresson dthyresson marked this pull request as ready for review October 27, 2023 16:30
@dthyresson dthyresson changed the title Draft: feature: Realtime setup and generator commands out of experimental and into main cli feature: Realtime setup and generator commands out of experimental and into main cli Oct 27, 2023
@dthyresson dthyresson added the fixture-ok Override the test project fixture check label Oct 27, 2023
@dthyresson dthyresson self-assigned this Oct 31, 2023
dthyresson and others added 2 commits November 3, 2023 12:33
Co-authored-by: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com>
Copy link
Collaborator

@Josh-Walker-GM Josh-Walker-GM left a comment

Choose a reason for hiding this comment

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

Tested locally and works well.

@dthyresson dthyresson enabled auto-merge (squash) November 3, 2023 16:50
jtoar added a commit that referenced this pull request Nov 13, 2023
Follow up to #9009 and #9205.

#9009 increased the bundle size of Redwood apps:

<table>
<tr><th>stable (v6.3.3)</th><th>v6.4.0 RC</th><th>% increase</th></tr>
<tr><td>

- Rendered: 1.03MB (100.00%)
- Gzip: 338.99KB
- Brotli: 290.87KB
    
</td><td>

- Rendered: 1.46MB (100.00%)
- Gzip: 461.74KB
- Brotli: 394.16KB

</td><td>

- Rendered: 41.75%
- Gzip: 36.21%
- Brotli: 35.51%

</td></tr>
</table>

I'm using
[rollup-plugin-visualizer](https://www.npmjs.com/package/rollup-plugin-visualizer)
on a newly-created Redwood app to get these numbers and treemaps. Here's
links to the full treemaps:
-
[stable](https://github.com/redwoodjs/redwood/assets/32992335/41cf4204-10de-4b69-a07a-7d6b980ead31)
- [v6.4.0
RC](https://github.com/redwoodjs/redwood/assets/32992335/f1a6a5bf-a260-45cb-8c97-f68b4fe0730d)

We don't have a history of bundle size metrics, so it's hard to tell
what the magnitude of this change is. But obviously in general, an
increase isn't good, especially if it's for a feature that isn't used
across the board.

One solution was mentioned in this thread:
#9009 (comment).
It was to have users import the link, that way if they didn't, Vite
wouldn't bundle it. The pushback there was more config for the user.

I paired with @Josh-Walker-GM on a solution that doesn't involve any
tradeoffs, except that it was work for us: we use Vite to remove the
file from the bundle if realtime isn't configured. No bundle size
increase if you're not using realtime, no config if you are!

Note that we need to watch out for
#9342 since it removes the
option from the toml file that this solution uses.

This was the main issue blocking v6.4.0, so now that it's resolved,
we're ready to ship next week.

**Update**

This PR was failing the serve smoke test consistently. At first I
thought it was because I didn't add the same logic to our webpack
config, so I went ahead and did that but it was still failing. After a
few dead ends, it turns out the logic I naively copied from the router
to conditionally render the splash page has had a bug all along:


https://github.com/redwoodjs/redwood/blob/699723910904d243ab153833b2d1a8e7494fcf40/packages/router/src/router.tsx#L120

You can see it easily by building and serving a Redwood app that doesn't
have a home page:

<img width="1186" alt="image"
src="https://github.com/redwoodjs/redwood/assets/32992335/b4ee1369-af45-4887-aacf-3217212bdc68">

This is because this line is transpiled into:

```js
var _splashPage = requireSplashPage();
// ...
if (shouldShowSplash && typeof _splashPage.SplashPage !== "undefined") {
```

And you can't get away with `undefined.SplashPage`. The reason we didn't
see it before is that hardly any user run `yarn rw serve` without a home
page.

Fixed by changing the module from a default `null` export to an empty
object export:
591ee5a.
jtoar added a commit that referenced this pull request Nov 13, 2023
Follow up to #9009 and #9205.

<table>
<tr><th>stable (v6.3.3)</th><th>v6.4.0 RC</th><th>% increase</th></tr>
<tr><td>

- Rendered: 1.03MB (100.00%)
- Gzip: 338.99KB
- Brotli: 290.87KB

</td><td>

- Rendered: 1.46MB (100.00%)
- Gzip: 461.74KB
- Brotli: 394.16KB

</td><td>

- Rendered: 41.75%
- Gzip: 36.21%
- Brotli: 35.51%

</td></tr>
</table>

I'm using
[rollup-plugin-visualizer](https://www.npmjs.com/package/rollup-plugin-visualizer)
on a newly-created Redwood app to get these numbers and treemaps. Here's
links to the full treemaps:
-
[stable](https://github.com/redwoodjs/redwood/assets/32992335/41cf4204-10de-4b69-a07a-7d6b980ead31)
- [v6.4.0
RC](https://github.com/redwoodjs/redwood/assets/32992335/f1a6a5bf-a260-45cb-8c97-f68b4fe0730d)

We don't have a history of bundle size metrics, so it's hard to tell
what the magnitude of this change is. But obviously in general, an
increase isn't good, especially if it's for a feature that isn't used
across the board.

One solution was mentioned in this thread:
#9009 (comment).
It was to have users import the link, that way if they didn't, Vite
wouldn't bundle it. The pushback there was more config for the user.

I paired with @Josh-Walker-GM on a solution that doesn't involve any
tradeoffs, except that it was work for us: we use Vite to remove the
file from the bundle if realtime isn't configured. No bundle size
increase if you're not using realtime, no config if you are!

Note that we need to watch out for
#9342 since it removes the
option from the toml file that this solution uses.

This was the main issue blocking v6.4.0, so now that it's resolved,
we're ready to ship next week.

**Update**

This PR was failing the serve smoke test consistently. At first I
thought it was because I didn't add the same logic to our webpack
config, so I went ahead and did that but it was still failing. After a
few dead ends, it turns out the logic I naively copied from the router
to conditionally render the splash page has had a bug all along:

https://github.com/redwoodjs/redwood/blob/699723910904d243ab153833b2d1a8e7494fcf40/packages/router/src/router.tsx#L120

You can see it easily by building and serving a Redwood app that doesn't
have a home page:

<img width="1186" alt="image"
src="https://github.com/redwoodjs/redwood/assets/32992335/b4ee1369-af45-4887-aacf-3217212bdc68">

This is because this line is transpiled into:

```js
var _splashPage = requireSplashPage();
// ...
if (shouldShowSplash && typeof _splashPage.SplashPage !== "undefined") {
```

And you can't get away with `undefined.SplashPage`. The reason we didn't
see it before is that hardly any user run `yarn rw serve` without a home
page.

Fixed by changing the module from a default `null` export to an empty
object export:
591ee5a.
@dthyresson dthyresson merged commit f0dd337 into redwoodjs:main Nov 17, 2023
32 checks passed
@Tobbe Tobbe modified the milestones: next-release, v6.5.0 Dec 1, 2023
@jtoar jtoar modified the milestones: v6.5.0, next-release Dec 5, 2023
@Tobbe Tobbe modified the milestones: next-release, v6.6.0 Dec 22, 2023
@jtoar jtoar modified the milestones: next-release, v7.0.0 Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixture-ok Override the test project fixture check release:feature This PR introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants