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

feat(server): add safety checks during dev #1568

Open
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

mbhrznr
Copy link
Contributor

@mbhrznr mbhrznr commented Aug 1, 2023

this is the second attempt to land #1489, as the initial version has been reverted due to unwanted side effects.

closes #475.
closes #1558.
closes #1678.

supersedes #539.
supersedes #1414.

this pr introduces the following check when being in dev mode:

  • only one _app.tsx is allowed per application and it must have a default export
  • only one 500.tsx and it must have a default export
  • only one 404.tsx and it must have a default export
  • pascal case or kebab case islands (island name) (this one became obsolete w/ 1.3)
  • routes must have exported handler or component
  • route patterns must be unique
  • route patterns w/ dynamic params must not have conflicts w/ other routes
  • if static override is used, ensure that there is no normal static directory
  • static file conflicts with routes (because static files have higher priority)
  • plugin doesn't call render/renderAsync
  • each defined module in a plugin must be a js/ts module
  • plugins should be present in the build snapshot

the functionality can be tested by changing the fixture task in deno.json to:

"fixture": "deno run -A --watch=static/,routes/ tests/fixture_dev_checks/dev.ts",

this time, the pr also contains unit tests for each individual check to (hopefully 🤞 ) prevent further mishaps.

@deer
Copy link
Contributor

deer commented Aug 1, 2023

You should go into each fixture and start up the dev server to confirm this isn't causing issues. Perhaps we could even add a test to assert that all the fixtures adhere to these checks.

@mbhrznr
Copy link
Contributor Author

mbhrznr commented Aug 1, 2023

You should go into each fixture and start up the dev server to confirm this isn't causing issues. Perhaps we could even add a test to assert that all the fixtures adhere to these checks.

will do!
currently i'm writing unit tests for each of the checks to hopefully cover all of the cases 🤞
will keep the pr in draft for the time being, yet wanted to bring it up asap again for transparency reasons.

i'd also incorporate the feedback and remarks from the first pr.

@deer
Copy link
Contributor

deer commented Aug 8, 2023

I see some changes of as -> satisfies. I guess this makes sense, but I wonder why just these three places? It seems like there should be a larger audit of the codebase to make this switch where appropriate. Therefore I think you should revert these from this PR, and then log an issue or open a separate PR if you're willing to take on the work yourself.

Some of the names in the error messages don't seem quite right:

See: _app
See: test
See: /custom.txt

I would expect:

See: routes/_app.tsx
See: routes/test.tsx
See: static/custom.txt
@mbhrznr
Copy link
Contributor Author

mbhrznr commented Aug 8, 2023

as always, thank you for the feedback!

I see some changes of as -> satisfies. I guess this makes sense, but I wonder why just these three places? It seems like there should be a larger audit of the codebase to make this switch where appropriate. Therefore I think you should revert these from this PR, and then log an issue or open a separate PR if you're willing to take on the work yourself.

sorry about that!
there wasn't an immediate need to do so, i just stumbled upon this while i was testing each of the available fixtures.
will revert these once i push the final changes.

Some of the names in the error messages don't seem quite right:

See: _app
See: test
See: /custom.txt

I would expect:

See: routes/_app.tsx
See: routes/test.tsx
See: static/custom.txt

you're absolutely right!
this has also been brought up in the initial pr and is something i'm currently working on.
this would be the final task before i'd comfortably consider this pr as "ready for review".

@mbhrznr mbhrznr marked this pull request as ready for review August 9, 2023 07:13
@mbhrznr
Copy link
Contributor Author

mbhrznr commented Aug 9, 2023

improved the warnings output as suggested.
also checked all of the fixtures to have some certainty that the dev checks don't introduce any unwanted behavior.

src/server/dev_checks.ts Outdated Show resolved Hide resolved
src/server/dev_checks.ts Outdated Show resolved Hide resolved
src/server/dev_checks.ts Outdated Show resolved Hide resolved
src/server/dev_checks.ts Outdated Show resolved Hide resolved
src/server/dev_checks.ts Outdated Show resolved Hide resolved
src/server/dev_checks.ts Outdated Show resolved Hide resolved
src/server/dev_checks_test.ts Show resolved Hide resolved
@mbhrznr mbhrznr marked this pull request as draft August 29, 2023 20:15
@deer
Copy link
Contributor

deer commented Aug 31, 2023

Seems like this should eventually cover #1678 (comment) as well.

@mbhrznr
Copy link
Contributor Author

mbhrznr commented Sep 4, 2023

Seems like this should eventually cover #1678 (comment) as well.

found a way to naively check the existence plugins in the current BuildSnapshotJson.
thanks for the hint!

@mbhrznr mbhrznr marked this pull request as ready for review September 4, 2023 22:39
@deer
Copy link
Contributor

deer commented Oct 30, 2023

#1950 (comment) is another example of a good check to add.

@deer
Copy link
Contributor

deer commented Feb 3, 2024

An addendum to #1558: we also need to think about conflicting islands as well. And if #2253 goes through, then also static files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants