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

documents.insert causes ViewDocument to render without new document ID #12

Closed
joserocha3 opened this issue Jun 25, 2017 · 2 comments
Closed
Assignees
Labels

Comments

@joserocha3
Copy link

joserocha3 commented Jun 25, 2017

The console throws an error because doc is a required prop of ViewDocument and the return statement setup causes ViewDocument to render before the new ID is truly returned. There is a subsequent render after the erroneous one that passing in the doc prop so the app still functions.

I am not enough of an expert to know if what I did is the correct fix, but here is it:

Error in console:

Warning: Failed prop type: The prop `doc` is marked as required in `ViewDocument`, but its value is `undefined`.

Problematic code found in imports/api/Documents/methods.js

'documents.insert': function documentsInsert(doc) {
    check(doc, {
        title: String,
        body: String,
    });

    try {
        return Documents.insert({owner: this.userId, ...doc});
    } catch (exception) {
        throw new Meteor.Error('500', exception);
    }
},

Changing the return statement to this alleviated the issue:

const documentId = Documents.insert({owner: this.userId, ...doc});
return documentId;
@justin88
Copy link

I'm getting the same warning in the console. This code doesn't solve the issue.

To test, make sure the documents are empty when adding a document. (Adding a second or third etc document does not trigger the warning.)

@cleverbeagle
Copy link
Owner

Fixed. A simple doc: Documents.findOne(documentId) || {}, in the container did the trick. The {} is enough buffer to not trip the prop type error when transitioning to the ViewDocument page.

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

No branches or pull requests

3 participants