1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
Commit graph

2504 commits

Author SHA1 Message Date
Tim Neutkens c07e27f2f1 7.0.3 2019-02-10 05:46:26 +01:00
Tim Neutkens 7c64336e9d Revert "should not change method to replaceState unless asPath is the same (#6033)"
This reverts commit ab46c45146.
2019-02-10 05:36:32 +01:00
Tim Neutkens 155423f26b
Bring in terser-webpack-plugin (backport #6231 to master) (#6232)
* Bring in terser-webpack-plugin (backport #6231 to master)

* Use correct path for ignore

* Comment out schema
2019-02-10 05:32:32 +01:00
tangye ab46c45146 should not change method to replaceState unless asPath is the same (#6033)
original code in `/lib/router/router.js`
```
  urlIsNew (pathname, query) {
    return this.pathname !== pathname || !shallowEquals(query, this.query)
  }
```
the urlIsNew compare `this.pathname` to an argument `pathname`
the invokers:
```
    // If asked to change the current URL we should reload the current page
    // (not location.reload() but reload getInitialProps and other Next.js stuffs)
    // We also need to set the method = replaceState always
    // as this should not go into the history (That's how browsers work)
    if (!this.urlIsNew(asPathname, asQuery)) {
      method = 'replaceState'
    }
```
the parameter here is `asPathname` destructured from `asPath`

so here is a problem when we reuse a single page rendered in two asPaths

pages/a.js
```
<>
  <Link href='/a'><a>goto a</a></Link>
  <Link href='/a' as='/b'><a>goto b</a></Link>
</>
```
If we navigate to page /a, then click 'goto b', actually the history is replaced, not pushed.
It is expected that history could be correctly pushed and popped as long as the browser url is changed.
2019-01-11 18:29:59 +01:00
Dale Inverarity f7477a9e2e Adding is @tailwind components; (#5897)
Without `@tailwind components;` plugins (like container which is added by default) will not work.
See: https://github.com/tailwindcss/tailwindcss/issues/446#issuecomment-378792892 for details
2018-12-16 16:23:18 +01:00
Adam Stankiewicz cd1d3640a9 Improve with-sentry example (#5727)
* Improve with-sentry example

* remove nonexisting keys from request and update errorInfo handling

* readd query and pathname

* read query and params and add pathname and query to client
2018-12-10 23:59:12 +01:00
Oscar Busk c867b0ce9c Fix paths when built on windows (#5795)
This PR Fixes #4920

So the problem is that when a next.js application is built on windows, the `pages-manifest.json` file is created with backslashes. If this built application is deployed to a linux hosting enviroment, the server will fail when trying to load the modules.

```
Error: Cannot find module '/user_code/next/server/bundles\pages\index.js
```

My simple solution is to modify the `pages-manifest.json` to always use linux separator (`/`), then also 
modify `server/require.js` to, when requiring page, replace any separator (`\` or `/`) with current platform-specific file separator (`require('path').sep`).

The fix in `server/require.js` would be sufficient, but my opinion is that having some cross-platform consistency is nice.

This change was tested by bulding an application in windows and running it in linux and windows, aswell as building an application in linux and running it in linux and windows. The related tests was also run.
2018-12-10 12:14:29 +01:00
Justin Stahlman c43975a927 Use more recent version of svg plugin (#5788)
The demo did not work. Updating to babel-plugin-inline-react-svg v1.0.1 did work.
2018-12-02 14:17:23 +01:00
Muhaimin CS ae8a49fe78 fix typo (#5451) 2018-10-15 12:16:05 +02:00
Tim Neutkens 45c554a328 7.0.2 2018-10-11 17:08:15 +02:00
Tim Neutkens e6d79bb88e
Remove pathname (#5428)
Same as #5424
2018-10-11 16:56:12 +02:00
Tim Neutkens ae56c7847f 7.0.1 2018-09-29 13:00:49 +02:00
Tim Neutkens c0945392f4
Upgrade webpack (#5330) 2018-09-29 12:43:55 +02:00
Tim Neutkens 8fb6f7d5b6 Use new import syntax in readme examples 2018-09-29 11:41:03 +02:00
Tim Neutkens 7f9d244d1f 7.0.1-canary.6 2018-09-29 10:15:27 +02:00
Tim Neutkens 2f618581cf Remove disabled plugin 2018-09-29 07:53:08 +02:00
Tim Neutkens 6c0ea2d424 7.0.1-canary.5 2018-09-29 07:25:47 +02:00
Henrik Wenz b065dafa52 Refactor head keys (#5326)
We don't need to `React.cloneElement`, twice.
2018-09-29 06:52:36 +02:00
Henrik Wenz df41997d50 Remove _containerProps context (#5327)
This PR removes the obsolete `_containerProps` context.
2018-09-29 05:24:27 +02:00
Tim Neutkens 30924ea1be 7.0.1-canary.4 2018-09-28 21:37:37 +02:00
Carlos 565b026e7b Added with-ts-node with Next js 7 example (#5204)
### Next js 7+ and Typescript 3+ Example

No babel, tsc, pure typescript usage
Made by [next-with-typescript plugin](https://github.com/echoulen/next-with-typescript)
2018-09-28 21:18:50 +02:00
Tim Neutkens 70c4b3d11c
Rename index.js to next-server.js (#5323) 2018-09-28 20:30:06 +02:00
Mert Can 2c6206d66c Package.json comma removed (#5322) 2018-09-28 15:37:19 +02:00
Tim Neutkens 0461413348
Don't require package.json at runtime (#5321)
* Remove obsolete check in dev-server

* Don’t require package.json at runtime

Inline the Next.js version at publish time, so that there’s no runtime dependency for this
2018-09-28 14:53:28 +02:00
Tim Neutkens 7f39aef912
Remove obsolete check in dev-server (#5320)
Remove `if(this.hotReloader)` as it's always guaranteed to be there.

https://github.com/zeit/next.js/pull/5317#discussion_r221233064
2018-09-28 14:32:26 +02:00
Tim Neutkens 881e5426e5 7.0.1-canary.3 2018-09-28 14:07:08 +02:00
Tim Neutkens 3f47a87c79
Initial dev server (#5317)
* Initial dev server

* Remove obsolete check

* Move hotReloader to dev-server

* Use parent renderErrorToHTML to remove dep on render.js

* Remove dev option from server itself
2018-09-28 14:05:23 +02:00
Luc f8dfe026ec Show warning if there is a title in _document.js's Head (#5160)
* show warning if there is a title in _document.js Head

* dont loop through children in production

* only 1 loop through this.props.children 💪

* also raise warning in test env

* check for null childs
2018-09-28 00:24:12 +02:00
Yuri Yakovlev ad93ff4b3e Remove transform-decorators plugin & Bump deps (#5232) 2018-09-27 23:42:06 +02:00
Tim Neutkens fb0b485299
Move out start method from server (#5315)
- This makes sure the Next.js renderer / server doesn't have a dependency on the `http` module.
- Splits out util functions for SSR only
- Removes obsolete methods / methods that weren't being tree-shaken
2018-09-27 21:10:53 +02:00
Tim Neutkens 20f3b6b284 7.0.1-canary.2 2018-09-27 17:46:42 +02:00
Tim Neutkens 4b18f00eee
Upgrade styled-jsx (#5312) 2018-09-27 17:42:20 +02:00
Tim Neutkens 944696e767 7.0.1-canary.1 2018-09-27 16:54:57 +02:00
Tim Neutkens 1c328a8450
Make sure dynamicIds are added when using function as importer (#5308) 2018-09-27 16:40:54 +02:00
Henrik Wenz f0f8229009 Update with-mobx-state-tree-typescript example (#5266)
To work with babel7 & next7.
2018-09-27 16:39:11 +02:00
Arek Mytych 5c9c7b877b Add language switch to with-react-i18next example (#5306) 2018-09-27 13:49:33 +02:00
Resi Respati 397daece42 with-typescript example updates (#5267)
* [with-typescript] Updated `@zeit/next-typescript` and typescript typings

* [with-typescript] Updated tsconfig to match new recommended config

* [with-typescript] upgraded dependencies, implement type-checking

* [with-typescript] add _document example, fixed tsconfig

* [with-typescript] updated README

* [with-typescript] updated example contents

* [with-typescript] adopt the Layout component from Flow example
2018-09-26 09:58:36 +02:00
Henrik Wenz 28a2bb36d6 Fix swallowed unhandled rejections on the server (#5273)
An upstream bug in webpack-dev-middleware caused unhandled rejections to be swallowed.
2018-09-26 02:12:00 +02:00
Tim Neutkens 6e4f0d8e70
Use getBrowserBodyText for HMR test (#5290) 2018-09-26 01:41:39 +02:00
Matthew Francis Brunetti 7961946c07 withApollo example - move from old HOC APIs to new function-as-child APIs (#5241)
Since version 2.1, react-apollo is exposing some new components that use the function-as-child (or render-prop) pattern to let you connect apollo-client magic with your components. See the blog article: [New in React Apollo 2.1](https://www.apollographql.com/docs/react/react-apollo-migration.html)

If I'm not mistaken, it's generally agreed that this pattern is (where it works) superior to the HOC pattern, for reasons that are best explained here: https://cdb.reacttraining.com/use-a-render-prop-50de598f11ce 

So I updated the with-apollo example to use the new API, and IMO this code is much simpler and natural to read and understand, especially if you are not already familiar with Apollo's HOC APIs.

I broke up my changes into separate commits, for easier review. Commits with "Refactor" in the message accomplish the goal of switching to the new APIs while minimizing line-by-line differences (select "Hide whitespace changes" under "Diff settings"). Commits with "Clean up" in the message follow up the refactoring with trivial things like reorganizing code sections, renaming variables, etc.

For the components doing mutations, I chose not to use the `Mutation` component, since that doesn't really make sense to me; a mutation is something that happens at a point in time, so it's not meaningful to represent a mutation in the markup, which exists for a period of time. All that component does is expose a `mutate` function for a single specified mutation, and `result` data for a single firing of the mutation (which we don't need anyways; apollo handles updating the local data with the result). To me it seems simpler and more flexible to just get the apollo client via `ApolloConsumer` and call `.mutate()` on it. 

In case anyone is interested, here's what my version of `PostUpvoter` using the `Mutation` component looked like:

 <details>

```jsx
import React from 'react'
import { Mutation } from 'react-apollo'
import { gql } from 'apollo-boost'

export default function PostUpvoter ({ votes, id }) {
  return (
    <Mutation mutation={upvotePost}>
      {mutate => (
        <button onClick={() => upvote(id, votes + 1, mutate)}>
          {votes}
          <style jsx>{`
            button {
              background-color: transparent;
              border: 1px solid #e4e4e4;
              color: #000;
            }
            button:active {
              background-color: transparent;
            }
            button:before {
              align-self: center;
              border-color: transparent transparent #000000 transparent;
              border-style: solid;
              border-width: 0 4px 6px 4px;
              content: '';
              height: 0;
              margin-right: 5px;
              width: 0;
            }
          `}</style>
        </button>
      )}
    </Mutation>
  )
}

const upvotePost = gql`
  mutation updatePost($id: ID!, $votes: Int) {
    updatePost(id: $id, votes: $votes) {
      id
      __typename
      votes
    }
  }
`
function upvote (id, votes, mutate) {
  mutate({
    variables: { id, votes },
    optimisticResponse: {
      __typename: 'Mutation',
      updatePost: {
        __typename: 'Post',
        id,
        votes
      }
    }
  })
}
```

</details>

###

I'm happy with where things are at here, but I'm more than happy to address any comments, concerns, ideas for improvent!

Thanks!
2018-09-26 01:32:41 +02:00
Tim Neutkens db216e0086
Even more reliable error-recovery tests (#5284) 2018-09-26 01:04:15 +02:00
Tim Neutkens 139bc40fb5
More reliable error-recovery tests (#5281)
As they were failing intermittently, this PR tries to solve that.
2018-09-25 16:54:03 +02:00
Tim Neutkens bb06f50747 7.0.1-canary.0 2018-09-25 15:28:51 +02:00
Tim Neutkens 42736c061a
Introduce dynamic(() => import()) (#5249)
* Add failing tests

* Upgrade wd module

* Pass dynamic import webpack ids to the client side

* Pass through webpack ids to initalializer and only use those

* Compile dynamic(import()) to dynamic(() => import())

* Default dynamicIds

* Use forked hard-source-plugin

* Possibly fix test

* Make tests fail less intermittently

* Temporarily disable hard-source in production

* Make sure dynamic import chunks are unique

* Disable hard-source

* Log html if error is thrown

* Fix test
2018-09-25 15:27:09 +02:00
Zack Tanner 9854c342e1 #5620: Fix react-i18next example to properly SSR (#5265)
This fixes https://github.com/zeit/next.js/issues/5260 by making sure that `index.js` has `getInitialProps` defined on the page exported component, not the child component.

When fixing that, I uncovered an issue where the server side rendered HTML did not match the clientside HTML, so I reworked _app.js to use the `i18nextprovider` component which has props to hydrate the initial data (for SSR), and makes sure the correct i18n instance is passed to all child components through context.

Before:
```html
<!DOCTYPE html>
<html>
   <head>
      <meta charSet="utf-8" class="next-head"/>
      <link rel="preload" href="/_next/static/development/pages/index.js" as="script"/>
      <link rel="preload" href="/_next/static/development/pages/_app.js" as="script"/>
      <link rel="preload" href="/_next/static/development/pages/_error.js" as="script"/>
      <link rel="preload" href="/_next/static/runtime/webpack.js" as="script"/>
      <link rel="preload" href="/_next/static/runtime/main.js" as="script"/>
   </head>
   <body>
      <div id="__next"></div>
      <script src="/_next/static/development/dll/dll_4a2ab6ce0cb456fbfead.js"></script><script>__NEXT_DATA__ = {"props":{"pageProps":{}},"page":"/","pathname":"/","query":{},"buildId":"development"};__NEXT_LOADED_PAGES__=[];__NEXT_REGISTER_PAGE=function(r,f){__NEXT_LOADED_PAGES__.push([r, f])}</script><script async="" id="__NEXT_PAGE__/" src="/_next/static/development/pages/index.js"></script><script async="" id="__NEXT_PAGE__/_app" src="/_next/static/development/pages/_app.js"></script><script async="" id="__NEXT_PAGE__/_error" src="/_next/static/development/pages/_error.js"></script><script src="/_next/static/runtime/webpack.js" async=""></script><script src="/_next/static/runtime/main.js" async=""></script>
   </body>
</html>
```

After: 
```html
<!DOCTYPE html>
<html>
   <head>
      <meta charSet="utf-8" class="next-head"/>
      <link rel="preload" href="/_next/static/development/pages/index.js" as="script"/>
      <link rel="preload" href="/_next/static/development/pages/_app.js" as="script"/>
      <link rel="preload" href="/_next/static/development/pages/_error.js" as="script"/>
      <link rel="preload" href="/_next/static/runtime/webpack.js" as="script"/>
      <link rel="preload" href="/_next/static/runtime/main.js" as="script"/>
   </head>
   <body>
      <div id="__next">
         <h1>This example integrates react-i18next for simple internationalization.</h1>
         <div>
            <h1>welcome to next.js</h1>
            <p>This example integrates react-i18next for simple internationalization.</p>
            <p>test words for en</p>
            <div><button>fire in the wind for en</button></div>
            <p>You can either pass t function to child components.</p>
            <p>Or wrap your component using the translate hoc provided by react-i18next.</p>
            <p>Alternatively, you can use <code>Trans</code> component.</p>
            <a href="/page2">Go to page 2</a><br/><a href="/page3">Go to page 3 (no hoc)</a>
         </div>
      </div>
      <script src="/_next/static/development/dll/dll_4a2ab6ce0cb456fbfead.js"></script><script>__NEXT_DATA__ = {"props":{"pageProps":{"i18n":null,"initialI18nStore":{"en":{"home":{"welcome":"welcome to next.js","sample_test":"test words for en","sample_button":"fire in the wind for en","link":{"gotoPage2":"Go to page 2","gotoPage3":"Go to page 3 (no hoc)"}},"common":{"integrates_react-i18next":"This example integrates react-i18next for simple internationalization.","pureComponent":"You can either pass t function to child components.","extendedComponent":"Or wrap your component using the translate hoc provided by react-i18next.","transComponent":"Alternatively, you can use \u003c1\u003eTrans\u003c/1\u003e component."}}},"initialLanguage":"en-US"}},"page":"/","pathname":"/","query":{},"buildId":"development"};__NEXT_LOADED_PAGES__=[];__NEXT_REGISTER_PAGE=function(r,f){__NEXT_LOADED_PAGES__.push([r, f])}</script><script async="" id="__NEXT_PAGE__/" src="/_next/static/development/pages/index.js"></script><script async="" id="__NEXT_PAGE__/_app" src="/_next/static/development/pages/_app.js"></script><script async="" id="__NEXT_PAGE__/_error" src="/_next/static/development/pages/_error.js"></script><script src="/_next/static/runtime/webpack.js" async=""></script><script src="/_next/static/runtime/main.js" async=""></script>
   </body>
</html>
```
2018-09-24 12:13:38 +02:00
John Leon ce8b301f24 Fix for with-ant-design-less for next7.0 (#5263)
* Update .babelrc

babel-plugin-transform-decorators-legacy does not exist in babel 7 in replace use @babel/plugin-proposal-decorators

* Update package.json

Acording the last commit please,  test this example , will be work .
2018-09-24 00:03:38 +02:00
Adam Lane 3bb62928a6 example with-sentry note that server side logging available too (#5261)
Trivial note to remind anyone doing sentry that they should consider doing server side logging too.
2018-09-23 21:06:05 +02:00
Adam Lane 48d54c254f example with-apollo note that two render executions are expected (#5262)
Noting per https://github.com/zeit/next.js/issues/5050 for new users of Apollo that they should not be concerned about multiple renders.
2018-09-23 21:05:00 +02:00
Henrik Wenz 7ebcc5bec9 Eliminate context code based on process.browser (#5159)
* Allow deadCodeElemination when using process.browser

* Add process.browser test
2018-09-23 16:02:28 +02:00
Henrik Wenz 80a6160caf Update with-dynamic-import example (#5201)
Follow up on: https://github.com/zeit/next.js/pull/4639
2018-09-23 16:01:54 +02:00