* Update autoExport wording to automatic static optimization
* Add sufficiently informative error message
- Update other Next error message for consistency
* Implement feedback - add missing character
Co-Authored-By: Lukáš Huvar <lukas@huvar.cz>
* Fix TypeScript errors
* Update test from autoExport to automatic static optimization
- Also reflect new wording of error message for readability
* Add test for handle non-page in pages
- When target: severless
* Added the RouteUrl type and improved router types
* Added more tests for router types
* Add build test for typescript types
* Add next-env.d.ts to the typescript test
* Removed next-env.d.ts
* Added next-env.d.ts to gitignore
* Remove route url re-exports
* renamed PublicRouterInstance to be NextRouter
* export the Url type
* Replaced BaseRouter with NextRouter in server/utils
* Don't export the Url type
* Update tsconfig.json
Notably, this PR fixes `faunadb` which relies on `formidable`.
n.b. `formidable` is an unmaintained legacy npm package that uses practices not compatible with the modern ecosystem.
* Add default values for runtime config
* Add test to ensure default values are set
for runtime config
* Only add runtimeConfig if it's not empty
* Only add runtimeConfig if it's not empty
* Simplify default value adding
* Reduce bundle size
* remove comment changes
* Fix typos
* Add test for runtimeConfig in __NEXT_DATA__
* Change static method handling and pages revert
* Allow and reflect old behaviour
* Post should return 501
* Add back old test
* Invert logic
* Handle 501 for pages in separate location
* Remove usage of 501 HTTP status code
* Prevent information leak
* Add test
* Only 405 if the page exists -- 404 if it doesn't
* Handle sent responses
* Revert "Handle sent responses"
This reverts commit 5e9012ae29b611c25ed1e090756a25dbe3437182.
* Fix bad test
* Switch back to quiet
* Update test/integration/production/test/index.test.js
Co-Authored-By: JJ Kasper <jj@jjsweb.site>
* Add prerender PageConfig option
* Update PageConfig type
* Add inlining of data when pre-render is set and add tests
* Update types import
* Add check for props
* Rename prerender to experimentalPrerender for now
* Remove `withAmp` and do not expose `isInAmpMode`
This pull request removes the `withAmp` higher-order component in favor of the exported configuration object.
Retaining this backwards compatibility isn't worth the extra maintenance burden, given it hasn't been released for very long and the migration is ultra-simple.
I'm 👎 on retaining backwards compatibility just for the sake of it.
Migration example follows. I'm willing to write a codemod if reviewers feel it's necessary.
*Before*
```js
import { withAmp } from 'next/amp'
function Home() {
return <h1>My AMP Page</h1>
}
export default withAmp(Home)
// or
export default withAmp(Home, { hybrid: true })
```
*After*
```js
export default function Home() {
return <h1>My AMP Page</h1>
}
export const config = {
amp: true,
// or
amp: 'hybrid',
}
```
* Fix { amp: 'hybrid' }
Co-Authored-By: JJ Kasper <jj@jjsweb.site>
* Update helper function to invoke only on get
* Tests for body parsing
* Update api-utils.ts
* Update next-server.ts
* Update packages/next-server/server/next-server.ts
Co-Authored-By: JJ Kasper <jj@jjsweb.site>
* Fix TypeScript typing
This correctly defines `process.browser` instead of `process.env.browser`.
It also removes `process.crossOrigin` because it's not found in our documentation anywhere and is mostly used for internal purposes.
* Make sure `process.browser` doesn't throw a type error
* Split globals from Next.js module
* Allow `test` as a valid NODE_ENV
* Fix type assignment
* Make sure global types get published
* Fix test
* Dynamic Routes: Change impl from $param to [param]
* Update expected test snapshot
* Update test to use new syntax
* Update test file
* Test more behavior
* Update route sorter for new param syntax
* Update dynamic routing tests
* Update danging test file
* Tweak test
* Fix dev and update tests
* Add handling for invalid pages during autoExport
* Add err.sh link for invalid page export
* Fix typo
* Apply suggestions from code review
Co-Authored-By: Tim Neutkens <tim@timneutkens.nl>
* Add export const config support and make withAmp a no-op
* Use babel plugin for PageConfig
* Fix serverless-loader exports
* Add backwards compatibility for withAmp
* Default `target` in `loadConfig` instead of `next build`
We should set the target from the environment variable during `loadConfig` instead of in `next build`. This ensures all other locations in Next.js that rely on `config` can read the correct value to toggle behaviors.
* Use object destructuring
* Add tests for builder target
* Run start with serverless
* Adjust Flying Shuttle message
This adjusts the flying shuttle message for when a shuttle is not found or cannot be reused to reduce confusion to the user opting into the feature.
* Tweak message
* Cookies and Query parsing for API request
* Adding JSON and SEND
* First body parsing
* Body parsing
* Remove extra try catch
* Fix tests
* Only server bundling for API routes
* Update packages/next-server/server/api-utils.ts
Co-Authored-By: Tim Neutkens <tim@timneutkens.nl>
* Revert on demand server changes
* Use content-type for parsing
* Update packages/next-server/server/api-utils.ts
Co-Authored-By: Jan Potoms <potoms.jan@gmail.com>
* Add tests for server compilation
* Add body limit
* Change API to function chaining
* Limit test
* Refresh query on mount for exported pages
* Make sure to only refresh query if it is different
* Only update if search isn't empty
* Merge pre-rendered query values with
current query values
* Remove dynamic restriction for autoExporting
* Update dynamic routing test fo autoExport
* Remove autoExport from client-navigation test
* Remove logs and update trailing slash config
* Update nextExport tests in client-navigation
* Disable autoExport in export suite
* Upgrade to latest AMP toolbox optimizer
* Remove amphtml from AMP only and update tests
* Update tests
* Apply suggestions from code review
Co-Authored-By: Joe Haddad <timer150@gmail.com>
* Run prettier over packages/**/*.js
* Run prettier over packages/**/*.ts
* Run prettier over examples
* Remove tslint
* Run prettier over examples
* Run prettier over all markdown files
* Run prettier over json files
* Add canonicalBase config to allow setting
absolute path for canonical link
* Make sure canonicalBase is set for
export and serverless
* Move canonicalBase to amp.canonicalBase
* Update tests with canonicalBase config
* Update tests
* run lint-fix
* Fix canonicalBase config parsing
* Fix canonicalBase during export
* Update amphtml tests
* Update escape string regexp operators
* temp
* Extract getRouteRegex func
* First iteration of dynamic routing for production only
* Correctly order prod
* Add serverless support
* Single line it
* noop routes
* Format doc
* Fix dynamic routing for dev
* Add flag for dynamic routing
* Update packages/next-server/lib/router/router.ts
Co-Authored-By: JJ Kasper <jj@jjsweb.site>
* remove example
* Add router tests
* Format code
* Sort routes
* Update to not use posix path methods
* Add automatic exporting of pages with no getInitialProps
* Add support for exporting serverless to static
and serving the html files during next start
* Fix missing runtimeEnv when requiring page, re-add warning
when trying to export with serverless, and update tests
* Update flying-shuttle test
* revert un-used pagesManifest change
* remove query.amp RegExp test
* Fix windows backslashes not being replaced
* Re-enable serverless support for next start
* bump
* Fix getInitialProps check
* Fix incorrect error check
* Re-add check for reserved pages
* Fix static check
* Update to ignore /api pages and clean up some tests
* Re-add needed next.config for test and correct behavior
* Update RegExp for ignored pages for auto-static
* Add checking for custom getInitialProps in pages/_app
* Update isPageStatic logic to only use default export
* Re-add retrying to CircleCi
* Update query during dev to only have values
available during export for static pages
* Fix test
* Add warning when page without default export is
found and make sure to update pages-manifest
correctly in flying-shuttle mode
* Fix backslashes not being replaced
* Integrate auto-static with flying-shuttle
and make sure AMP is handled in flying-shuttle
* Add autoExport for opting in
* Use intersection observer to preload
links that are in viewport
* Clean up names
* Check for window before returning observer
* update check for IntersectionObserver
* Remove duplicate IntersectionObserver checks
* Add test for prefetching links in viewport
* Remove loadGetInitialProps from _app and fix
cache-control header not being
* Update to still use loadGetInitialProps
in _app since it's simpler
* Add test for cache-control header with custom _app
* Add --no-subfolders argument to next export
* Use experimental.exportTrailingSlash instead of a cli flag
* Add experimental.exportTrailingSlash documentation
* Add tests for export with experimental.exportTrailingSlash
* Remove docs
* Remove comment
* Make styles compatible in AMP mode
* bump
* Update to parse styles from fragment for
backwards compat in AMP mode
* Add test for AMP styles fragment support
We also close the connection when the window is in the background and re-connect when it is brought to the foreground. This prevents us from using up too many connections.
This PR adds the `_error`-page as an `404.html`-export, even when it is not explicitly defined in a custom `exportPathMap`.
It also fixes two false negative tests related to this. Previously the tests were matching the fallback 404-page from the test-server, rather than the `404.html`-page from next, which was actually not being generated. The test server is also not set up to serve `/404.html` as `/404` which the tests now reflect.
**Caveat**
In its current state, this PR removes `/404.html` from the `defaultPathMap` passed to the custom `exportPathMap`-functions, since it instead adds it after that function is run. While it is possible that someone is relying on this to exist, it is to my knowledge undocumented and also unlikely to be used for anything but merging it into the custom pathMap.
Since this would now merge `undefined` which would result in it being added later on anyway, I deemed it safe, but would be happy to undo that part of the PR if necessary as it was only cleanup.
**Examples**
As a way to demonstrate what this PR does, this is how examples changed:
* `basic-export` - Behaviour is unchanged, still has a `404.html`
* `with-static-export` - Now has a `404.html`
if `&=1` is used to point to the `amphtml` version of a page it get's escaped causing it to become `&amp=1` this fixes it to stay as `&=1`
Closes: #7038
* Update amphtml and canonical rels, put amp behind
experimental flag again, and update checking for amp query
* Fix typescript error
* Re-add flag to next.config.js
* Make sure AmpContext is available during _document
render and update filtering of script tags in AMP mode
* Update amphtml test to make sure
AmpContext is set for _document render
* Fix stray comma in render.tsx
* Add WithAmp to enable AMP support for
pages instead of .amp.js
* Update handling for exporting AMP
* Fix ampPath in export for / path and
revert isAmp logic to handle right
* Update amphtml test suite
* Add handling for noDirtyAmp during
export and update amp-export test suite
* Update serverless and export-default-map
test suites
* Update require-page tests
* Add Flying Shuttle tests
* Test second version of server
* Finish first version of tests
* Apply suggestions from code review
Co-Authored-By: Timer <timer150@gmail.com>
* Apply suggestions from code review
Co-Authored-By: Timer <timer150@gmail.com>
* Remove CLI and negative page building
* Remove select all tests
* Update test of getSpecifiedPages
* Prune old tests from snapshot
* Remove old flying shuttle tests
* Fix re-rendering on client after navigating
back from external site
* Clean up tagging before unload
* Add check for history.state 1/2
Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>
* Add check for history.state 2/2
Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>
* Add check for options
Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>
* Add test for navigating to external site and back
also added testing in safari and firefox
* Add test for query in url
* Do not clear the console
Its rude to clear the console, you may be sharing output with other processes even in tty mode.
* Remove unused dependency
* Dedupe and cleanup dev output without clearing
* use logError
* Remove exit handler
* Add next helper
* Add log helpers
* Switch store to log helpers and a shallow object compare
* Update other files to use new logging utility
* request => build
* Update ready on messages
* Use case insensitive matching
* Add amp request header and check for amp
query in serverless mode
* Add serverless test for an AMP page
* Update to handle querystring weirdness
* Update serverless test config
* Get all modules included in build
* Add tests
* Get all modules contained per entry chunk
* Sort files
* Add specialized page entry to manifest
* Split manifest into pages and chunks key
* Update test
* Use relative paths to build directory
* Update test
* Added amp-toolbox-optimizer and added
optimizing AMP pages as dirty and clean
* Fix amp-optimizer breaking serverless build
* Exclude amp-toolbox-optimizer from serverless build
* Added check to make sure hybrid AMP pages
optimize cleanly during export
* Add check to make sure noDirtyAmp is applied
Drops user `<script>` tags and shows a warning in AMP mode. Right now they are only dropped in production mode and left in dev mode so the validator shows its warning since it looks like conflicting props log messages are being cleared causing them to not show.
Closes: #6688
Update tests to setup webdriver stuff in `jest-environment` and re-use one browser session instead of spawning one for each webdriver call to prevent creating too many BrowserStack sessions.
* Add default viewport meta tag (fixes#6698)
* Do not inject default viewport when rendering an AMP document
* Remove redundant viewport on error page
* Plumb withSideEffect() to pass through props, then use that for isAmp.
* Add tests for viewport meta tag.
* Fix linting
* Update dedupes test
* Add err.sh link and pool validation results
to wait to show error until export is finished
* Fix wording in amp-export-validation err.sh
* Update validation error message
Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>
* Update ways to fix text
Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>
* Update why the error occurred wording
Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>
* Update wording some more
Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>
* Add more export tests for AMP
* Remove console.log
Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>
* remove extra line
Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>
* Break out client-navigation and rendering
test from basic test
* Try with parallelism dialed back to 3
* Update jest-junit for more compatible timings in CircleCI
* Bump to test timings
* Use filepath for suitename in jest-junit
* Store reports as artifacts
* Try using classname for timings
* Bump
* Remove reports from artifacts
* Add support for .amp.js pages and
resolving /page?amp=1 to page.amp.js
* Update amp tests
* Update example and clean up amp page resolving
* Add nested amp test
* page => normalizedPage
* Add type to page options
* Add handling of amp with all pageExtensions
and normalize page
* Make sure findPageFile only falls back to
amp if enabled
When overriding `config.resolve.alias` incorrectly webpack will throw an error because private-next-pages is not defined. This adds a more descriptive error explaining the error better.
Fixes: #6681
By default when `next export`ing a Next.js application we will automatically append a `/` to all urls to be fully compatible with the directory structure being output.
However since most platforms support directory indexes it makes sense to change this default in the future.
This PR adds `exportTrailingSlash` as experimental flag. We'll try this out for a bit on nextjs.org / zeit.co/docs before introducing it as new option.
The default value is `true` as this is the current behavior in stable Next.js.
```
{
experimental: {
exportTrailingSlash: false
}
}
```
⚠️ as with all experimental flags being added this is subject to breaking between canary/stable versions.
* Check for the user's home directory in the build output
* Output files on windows for debugging
* add process cwd
* try more paths
* Add branch for winblows
* Print info on error
* set proper env
* try fix
* Show a better error when someone throws undefined
* Update error wording
Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>
* Update error wording in test
Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>
* Update test and add check for statusCode
before updating error
### changes
#### remove trailing spaces
When I was using example I noticed trailing spaces.
So, this PR removes the trailing spaces of json file, README, and others.
`examples/with-jest-typescript/src/modules/cars/Overview.tsx` also has it, but this time it did not change as tslint error occurs at commit.
* Update to use the correct router instance in withRouter so error is
thrown when router method is used during SSR
* Revert changes to with-router and add error to methods on
direct router instance
* Extend Router and override methods with error instead
* Update ServerRouter, add err.sh, and add test
* Add warning on stalled page load possibly from too many tabs open
* Add test for stalled warning
* Update onDemand pinging to close on routeChangeStart and added
warning when onDemand handler detects multiple tabs from the same
browser
* Show error when `router` or `Component` are returned in _app.js
getInitialProps
* Update to only show error in dev mode
* Update packages/next-server/server/render.tsx
Co-Authored-By: ijjk <22380829+ijjk@users.noreply.github.com>
* make router UrlIsNew comparing method work as expected
* Remove shallow-equals from router and update urlIsNew check
* Remove shallow-equals test since it is no longer used
* Add integration test for asPath query
* AMP page reload
* Fix comment
* Skip dev files in production
* Polyfill event source
* Add HMR test for AMP
* Use webdriver
* Use a dynamic server for HMR test
* ffs
After talking with @timneutkens it was decided it'd be more streamlined to replace the onDemandEntries WebSocket with an alternative. Using the EventSource connection gives us these benefits over the WebSocket one:
- less code needed
- no extra server running
- no extra config for onDemandEntries
Relevant commit: f913aabe16
~~I needed to upgrade Standard to work with JSX fragment syntax.~~ This caused too much noise so I just stopped using Fragments.
Arguments that held the same name as one of the default commands were filtered out, causing issues.
For example `next build build` would get rid of the second `build` parameter.
Fixes#6263
Fixes#5347
The main issue is that we were waiting only 1 level of dynamic imports, so the dynamic imports nested inside other dynamic import files were not awaited. This would cause either a flash of loading states or you wouldn't see the loading state (because of preload) but it would then show a hydration warning in development.
Thanks to @arthens for providing the reproduction that I modelled the tests after.
After discussion, I added falling back to fetch based pinging when the WebSocket fails to connect. I also added an example of how to proxy the onDemandEntries WebSocket when using a custom server. Fixes: #6296
Closes: #6244
This will block the following keys:
```
NODE_.+
__.+
```
There doesn't seem to be a way to simulate a failed build or else I'd add tests for it.
* Set default `Error` status code to 404
This is an appropriate default behavior because:
1. When the server encounters an error, the `err` property is set.
2. When the client-side application crashes, the `err` property is set.
This means the "only" way to render the `/_error` page without an error
is when a page is not found (special condition).
Fixes#6243Closes#5437
* Add new integration test for client side 404
* single quotes
* Remove unused variable
* Standard needs to go away
* Whoops
* Check for null status code in res and err
* Only check response for valid statusCode
* Implement circular JSON err.sh link
* Add test for getInitialProps returning circular json
* Make test warn less
* Fix tests
* Add reference to original tests
Fixes#5363
I noticed this happening when making some changes on the nextjs.org/learn app. Basically we didn't apply updates when a warning was emitted from webpack. This would cause issues for users using eslint-loader or similar too.