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

Flash Messaging causes error with scaffold CRUD #714

Closed
thedavidprice opened this issue Jun 18, 2020 · 2 comments · Fixed by #715
Closed

Flash Messaging causes error with scaffold CRUD #714

thedavidprice opened this issue Jun 18, 2020 · 2 comments · Fixed by #715
Labels
bug/confirmed We have confirmed this is a bug

Comments

@thedavidprice
Copy link
Contributor

Flash Messaging error introduced via this PR #654

@cannikin @Terris I ran into the errors below running through local tests in preparation for cutting a new release. If you think this is a quick fix, please submit a path. Otherwise, I might revert the PR for now so we can get v0.11.0 out. Suggestions otherwise?

Steps to Replicate

  • Upgrade to 0.10.1-canary.26
  • Generate Scaffold for a model of your choosing
  • Create a New via UI

GraphQL mutation and queries run fine:

api | POST /graphql 200 7.382 ms - 25
api | 2020-06-18T05:32:01.232Z prisma-client Prisma Client call:
api | 2020-06-18T05:32:01.233Z prisma-client prisma.article.create({
api |   data: {
api |     title: 'hello',
api |     body: 'world'
api |   }
api | })
api | 2020-06-18T05:32:01.233Z prisma-client Generated request:
api | 2020-06-18T05:32:01.233Z prisma-client mutation {
api |   createOneArticle(data: {
api |     title: "hello"
api |     body: "world"
api |   }) {
api |     id
api |     title
api |     body
api |     createdAt
api |   }
api | }
api | 
api | POST /graphql 200 25.077 ms - 59
api | 2020-06-18T05:32:01.320Z prisma-client Prisma Client call:
api | 2020-06-18T05:32:01.320Z prisma-client prisma.article.findMany(undefined)
api | 2020-06-18T05:32:01.321Z prisma-client Generated request:
api | 2020-06-18T05:32:01.321Z prisma-client query {
api |   findManyArticle {
api |     id
api |     title
api |     body
api |     createdAt
api |   }
api | }
api | 
api | POST /graphql 200 4.152 ms - 125

Model

model Article {
  id        Int      @id @default(autoincrement())
  title     String
  body      String
  createdAt DateTime @default(now())
}
``
### `NewArticle.js` from Scaffold Generator
```js
import { useMutation, useFlash } from '@redwoodjs/web'
import { navigate, routes } from '@redwoodjs/router'
import ArticleForm from 'src/components/ArticleForm'

const CREATE_ARTICLE_MUTATION = gql`
  mutation CreateArticleMutation($input: CreateArticleInput!) {
    createArticle(input: $input) {
      id
    }
  }
`

const NewArticle = () => {
  const [createArticle, { loading, error }] = useMutation(
    CREATE_ARTICLE_MUTATION,
    {
      onCompleted: () => {
        navigate(routes.articles())
        addMessage('Article created.', { classes: 'rw-flash-success' })
      },
    }
  )

  const onSave = (input) => {
    createArticle({ variables: { input } })
  }

  return (
    <div className="rw-segment">
      <header className="rw-segment-header">
        <h2 className="rw-heading rw-heading-secondary">New Article</h2>
      </header>
      <div className="rw-segment-main">
        <ArticleForm onSave={onSave} loading={loading} error={error} />
      </div>
    </div>
  )
}

export default NewArticle

Browser ErrorBoundary Output

Unhandled Rejection (ReferenceError): addMessage is not defined

onCompleted
src/components/NewArticle/NewArticle.js:19

> 16 |   {
> 17 |     onCompleted: () => {
> 18 |       navigate(routes.articles())
>>19 |       addMessage('Article created.', { classes: 'rw-flash-success' })
> 20 | ^   },
> 21 |   }
> 22 | )

callOncomplete
node_modules/@apollo/react-hooks/lib/react-hooks.esm.js:468

MutationData.push.../node_modules/@apollo/react-hooks/lib/react-hooks.esm.js.MutationData.onMutationCompleted
node_modules/@apollo/react-hooks/lib/react-hooks.esm.js:478

(anonymous function)
node_modules/@apollo/react-hooks/lib/react-hooks.esm.js:415
@thedavidprice thedavidprice added the bug/confirmed We have confirmed this is a bug label Jun 18, 2020
@Terris
Copy link
Contributor

Terris commented Jun 18, 2020

@thedavidprice - so sorry about this. I'll submit a PR in a few minutes with a fix.

@thedavidprice
Copy link
Contributor Author

@Terris all good and huge thanks for the quick turnaround!

The yay/boo on this is that as of yesterday we have an early version of EtoE tests that helped catch this bug before releasing! We're all getting better at this slowly but surely 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/confirmed We have confirmed this is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants