"Maximum call stack size exceeded" When Using Slingshot on Meteor 1.4 - Solved


#1

I have previously used the edgee:slingshot package with success and have pretty much copied the code I used from another project. This code now does not work on this new project. I have updated to Meteor 1.4, I don’t know if this is part of what is causing this issue as this upgrade to 1.4 has also caused me 1,000 other issues in getting back to working on my project. :open_mouth:

So I am getting this error when running uploader.send():

underscore.js:113 Uncaught RangeError: Maximum call stack size exceeded

Here’s some of my code if anyone can see something that may be causing this:

client:

...
'change #new-blog-post-image-upload': function ( event, template ) {
      let file = $('#new-blog-post-image-upload');
      let options = {
         event: event,
         template: template,
         file: file[0].files[0]
      };

      Modules.uploadBlogImage( options );

     ...
   }
...

let _addUrlToDatabase = ( options, url ) => {
   Meteor.call( 'store.blog.image', url, ( error ) => {
      if ( error ) {
         ...
      } else {
         ...
      }
   });
};

Modules.uploadBlogImage = ( options ) => {
   let meta = options;
   const uploader = new Slingshot.Upload( 'uploadBlogImage', meta );

   uploader.send( options.file, ( error, url ) => {
      if ( error ) {
         console.log( 'err' );
      } else {
         console.log( 'success' );
         _addUrlToDatabase( options, url );
      }
   });
}

Server:

Slingshot.fileRestrictions( "uploadBlogImage", {
   allowedFileTypes: [ "image/png", "image/jpeg", "image/gif" ],
   maxSize: 12 * 1024 * 1024
});

Slingshot.createDirective( "uploadBlogImage", Slingshot.S3Storage, {
   bucket: "bucket-name",
   acl: "public-read",
   authorize: function ( file, meta ) {
      return true;
   },
   key: function ( file, meta ) {
      return file.name;
   }
});

Methods.js:

...
'store.blog.image': function ( url ) {
     console.log('method running');
     return BlogMedia.insert({
         createdAt: new Date(),
         createdBy: Meteor.userId(),
         url: url
     });
 }
...

The slingshot version is the same version as my other projects, 0.7.1. But like I said, I am not 100% sure this error has anything to do with my code or Slingshot…I am thinking something else went wrong when updating Meteor. I can’t seem to find help because the error thrown is really vague.


#2

The only time I’ve seen that error is by accidentally introducing recursion.

Can you profile your code with Chrome inspector? (I’m assuming this is occurring on the client).


#3

Yes it’s on the client. And I’m not quite sure how to profile my code on Chrome inspector? I suppose I should figure out how that works.


#4

LOL. Yes - it’s really useful :slight_smile:


#5

Is it possible to update the project that has slingshot working to 1.4 and test that it works or not? This way at least you can rule out if it’s a 1.4 issue or not.


#6

Not atm, because that project has so many errors I can’t even get it to update. But what I’m thinking about doing is creating a fresh project and testing it for both 1.3 and 1.4

Edit: My old project is still on 1.2.1 :open_mouth:


#7

My advice, get a baseline. Start out in 1.3 and get it working with slingshot.

Then check the code into github. Then create a 1.4 branch off the master branch (the branch that’s using 1.3) and do a meteor update --release 1.4.x on that branch. See if that breaks the code.

This way you will know if you’re fighting a slingshot issue or a 1.4 issue.

I’m using slingshot in Meteor 1.3.5.1 and it works fine, so I’m interested how this works out in 1.4.


#8

It’s definitely something to do with my code. Because I’ve tested it and is not working anywhere…except when I redid the code to match EXACTLY what my old project was using, and it worked. I haven’t spotted where the exact mistake is yet, but apparently when I edited the code to shorten it a little I messed it up :confused:

Edit: Yes I can definitely confirm…I redid the code entirely and everything seems to work fine in 1.4