Skip to content

Next reorg#1559

Closed
drwpow wants to merge 38 commits intonextfrom
next-reorg
Closed

Next reorg#1559
drwpow wants to merge 38 commits intonextfrom
next-reorg

Conversation

@drwpow
Copy link
Member

@drwpow drwpow commented Oct 15, 2021

Changes

This is quite a bikeshed, but wanted to get some feedback. Talked this over with Nate and we’d like to take a little time to organize the structure a bit better before committing to it.

Background

The next branch has changed a lot since the first cut of Astro! Though the core principles remain the same, I think we struggled to determining which code ran where (I know I did). Given any code file, it was difficult to determine which context it ran in, and at what point in the chain.

This seems to be even more important in Vite-land, where running code inside Vite executes more differently than top-level Astro (especially given then current ESM / SSR problems).

This PR

This PR proposes the following rules, inspired by SvelteKit and Vite’s:

  • @types/: self-explanatory
  • cli/: self-explanatory.
  • core/: it’s easy to just say “this is Astro core” but that’s vague. This is code that runs in the top Node context. Nothing here gets run inside Vite SSR, nor does it contain browser code. It contains a few subfolders:
    • build/,dev/, preview/: the main actions of Astro. Somewhat self-explanatory
    • ssr/: this sets up Vite SSR and compiles .astro files.
    • A few other files in here related to the above
  • runtime/: this was a bit of a “catchall” before but I’d like to propose that runtime now only means code that runs in a different context. It contains 2 subfolders, for the 2 contexts:
    • client/: this code executes in the browser. It contains hydrations for JS.
    • server/: this code gets called within vite.ssrLoadModule(). So anything in here will get run inside Vite.
  • vite-plugin-*: the Vite plugins were moved out into their own folders. Perhaps eventually we’ll release these as separate packages, but that’s just hassle for now. Still, I think it would be good to try and isolate these Vite plugins not only for possible future release, but also debugging.

All the existing code was moved into one of these folders.


Put another way, it solves the following issues both from next as well as some from main:

  • “SSR”: this term has clear meanings to most of us, but when naming things, it would get muddied between what was managing the SSR vs what was being SSR’d. And often those 2 things don’t touch.
  • internal/: this was fine, however, at different stages this would pull in files from other contexts which meant this wasn’t the only stuff that would get executed within SSR
  • runtime/: this was a muddle of code executing in all different contexts. Code that would load the SSR, and code that would execute within SSR, would be side-by-side. That means you’d have to watch your imports!

Testing

Tests should pass

Docs

After next gets merged, we can probably update CONTRIBUTING.md with some of this info (or, I’m partial to README files within folders myself, even if they’re just stubs explaining the goal of a folder)

FredKSchott and others added 30 commits September 30, 2021 10:00
* Try mocha/chai test runners

* Disable failing smoke test for now

Will revert when next can build docs

* Enable mocha in parallel mode

* Remove warning

* Update docs

* Fix Windows bug

* Fix internal imports

* Fix styles
* fix(logger): locale parsing
* Fixed issue of compiler crash when "c" locale was encountered
* Return default locale if parsed locale is less than 2 chars long

* chore: add changeset
* Add back in support for children

* Be more careful
* Enables most slot tests

* Use spreadAttributes
* feat: add hydration to Solid renderer

* fix: intersection observer, move script to the end

Co-authored-by: Ryan Carniato <ryansolid@gmail.com>
* [next] Support for custom elements

* Fix eslint errors

* eslint again
FredKSchott and others added 5 commits October 12, 2021 16:09
* fix Astro.fetchContent

* fix(fetchContent): cast type

Co-authored-by: Nate Moore <nate@skypack.dev>
* Move hydration to the compiler

* Move extracting url, export to util fn
* Implements top-level Astro + Astro.resolve

* Fix linting
* chore: update vite

* fix(renderers): point renderers to resolved server/client entrypoints
@changeset-bot
Copy link

changeset-bot bot commented Oct 15, 2021

⚠️ No Changeset found

Latest commit: e711d03

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@matthewp
Copy link
Contributor

sgtm

@drwpow
Copy link
Member Author

drwpow commented Oct 15, 2021

sgtm

lol I thought you would have more feedback! If this sounds like an improvement we can try it out, but I’m also happy for this not to be the final structure and for others to have say

Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

Very in favor of all of these changes!

A few small notes.

  • IIUC I'm pretty sure packages/astro/src/core/ssr/{html,h}.ts can both be removed. They're holdovers from Astro Classic™
  • It'd be great to add a README.md file to each directory to repeat what kind of code lives in this directory, as you've outlined in this PR. Useful to colocate that info with the code and it will showup on GitHub as folks are browsing the repo.

@drwpow
Copy link
Member Author

drwpow commented Oct 15, 2021

IIUC I'm pretty sure packages/astro/src/core/ssr/{html,h}.ts can both be removed. They're holdovers from Astro Classic™

Cool. I wasn’t sure if we still needed them or not as “the default/fallback renderer” but you’re right—our compiler spits out valid HTML now! And we have that $$render function now.

Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for updating 🎉

'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
Copy link
Member

Choose a reason for hiding this comment

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

In favor of this change!

@matthewp
Copy link
Contributor

lol I thought you would have more feedback!

Not really, sorry. I'm pretty tolerant of any organization as long as things aren't so deeply nested that it's hard to find files without search, and this one seems fine in that regard. I'm pretty unopinionated on where files live otherwise.

@drwpow
Copy link
Member Author

drwpow commented Oct 16, 2021

Feedback incorporated! Closing this because of the gnarly rebase in favor of #1569.

@drwpow drwpow closed this Oct 16, 2021
@drwpow drwpow deleted the next-reorg branch October 16, 2021 00:15
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.

5 participants