-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Strange behavior on Safari IOS #373
Comments
I am encountering this as well, but it occurs in Safari 6 on OS X and only when the console is disabled (wondering if this means it's a Safari bug?). We aren't using For me, the error is thrown in that quotedString function. Basically, it appears Handlebars is unable to track the scope of "this" in Safari 6. |
I've found a rogue block helper in one of our templates that was unnecessary. Now everything seems to work for now. Wondering why it worked in the first place but as long as it works I'm happy with it. The context was an object and this template is invoked approx. 200 times.
|
I have worked around this in our app by compiling templates in Node as part of our build, which is something I've been meaning to do anyway. Works fine that way! |
I meet exactly the same problem recently, wondering whether it is a bug in Handlebars ? or some mistake template I wrote? Or is there any way to avoid this? |
@Furizaa my template is like
and the problem is the same as what you have described, I want to know how did you fix this? change the template usage? I don't want to change my build process to make the template be build in node, wish there is some easy way to work around this... |
The stuff I wrote above is all I know about it. We had a severe error in out template that skyrocketed the complexity. For other projects we now build out templates with Node and never encountered the error again. |
I am certain it's not a bug in Handlebars, but a bug in Safari 6. Compiling the templates in Node and saving them as |
@misteroneill @Furizaa Thank you all the way, I will have a try to pre-compile the templates. Wish it would not be too difficult to change all my project's templates into pre-compiled ones, I have not considered this way before. : ) I have googled a lot on how to use pre-compiled handlebars templates, could not find any tutorial which shows how to put the pre-compiled templates work well with Require.js and Backbone.js, wondering whether there are some articles showing the best practices on doing this right? Is https://github.com/SlexAxton/require-handlebars-plugin a good choice? Best. |
The Handlebars binary provided by the
That's all there is to it. Dead simple. You may want to minify it using |
@misteroneill thanks again for the information on how to compile the templates. I have got a big project now, with about 100 template files included by require.js, using require.js text plugin, in the way below:
Until this problem, I haven't considered to manage and reference my template files in another way, but now, I think there maybe some projects already solved this problem before, including the solution to use the un-compiled version in development and the compiled templates after build, all transparent to upper level developer. So when I say I want to find some best practice on this topic, I mean I want to find some articles talking how to manage the templates in a better way. I've found some useful information here: Still wondering how other projects solved this problem. I'm go on looking for some methods to manage all my template files in a better way, also any other projects that have already solved this problem or information would be great appreciated! |
Solved, use grunt http://gruntjs.com/ to build the whole project, invoke r.js and compile all templates in grunt is great. Thanks again. |
I managed to create a minimal test case for this problem: http://jsbin.com/ezidox/25 Only fails with Safari 6 and with the console closed. Since it only starts failing after a few iterations, it looks like it could be due to a JS engine optimisation being too aggressive. It definitely looks like a bug in Safari 6. |
I have published a patched Handlebars 1.0.rc2 with the fix suggested in #440: https://s3-eu-west-1.amazonaws.com/le-public/handlebars-quoted-string-fix.js This seems really dirty to me but it solves some of the problems associated with the Safari bug. |
It seems that my fix is useful just to avoid Safari errors, but some templates don't get rendered. I think the problem is probably is generated by the context lost. Safari seems indeed to loose the reference to {{this}} |
I'm still having this problem. The simple bug fix renders empty strings where there should be content. Something a simple as:
Just renders as:
How the heck do I get around that? |
Are you using version rc3 of handlebars? On Tuesday, February 26, 2013, psayre23 wrote:
|
Yes. I originally had rc1, but when I ran into this problem I upgraded to rc3. My templates still crash, but now with a different error. It's now an error coming from within the compiled code. I'll send a stack trace as soon as I can. ~ Paul On Feb 25, 2013, at 11:07 PM, Leonard Ehrenfried notifications@github.com wrote:
|
Here's my stack:
The error happens randomly, sometimes not at all. And it only happens on iPad iOS 6.1.*. This morning, I tried precompiling from Node. This works for the short term, but long term I can't force each developer on my team to recompile after every change during development. I'm on my 5th day of debugging, so let me know what else I can provide. ~ Paul |
Can you link to the tagged version of that handlebars.js file so the line On Tue, Feb 26, 2013 at 11:03 AM, psayre23 notifications@github.com wrote:
|
I think you will get a better response from the handlebars developers If the exception isn't thrown on every compile, then run the example in a On Tuesday, February 26, 2013, psayre23 wrote:
|
Just wanted to fill my stuff in here, since i saw it too and spent a couple of hours with it today (Chrome Canary 27.0.1453.2). Leaving this for the next poor person to encounter this First of all this problem seems very hard to reproduce consistently, it comes and goes (i could see it on every other reload for about 30 min, then it was completely gone). So i think all we can do for the moment is to gather information about it here. Here's how the node looked for me that cause the problem:
Notice something funky on the idNode: Problem is, since i'm not super-familiar with the handlebars source, at the time i had tracked it down to the Handlebars.AST.IdNode constructor, i stopped seeing the error for some reason. If you see this bug again, i'd ask you to:
Thanks |
I managed to get around this bug by using {{./this}} insted of {{this}}. Using version 1.0.0. |
I had a similar problem with identical symptoms. Upon opening the error console I would see a javascript 'type error' with the error disappearing when the developer console was open. None of the recommendations here and on SO (precompile, rename to compiled file to have .js extension) fixed it for me though. After a few of frustrating debugging, I was able to work around it. One of my JSON properties was a number. Handlerbars.Utils.escapeExpressions would throw the type error in the string.toString() method when trying to render that property. Funnily enough, if I added a console.log(typeof string); line, the error would disappear. My fix/workaround was to just make it a string in the JSON. |
Seem to be experiencing the exact same bug myself using Handlebars 2.0.0-alpha4 with Chrome 36. Canary and Chrome Beta (37) seem to be unaffected. |
I suddenly encountered this same bug in Chrome 36 with Handlebars 1.0.rc.1. Updating handlebars to version 1.3.0 seemed to do the trick. |
FYI, we encountered a very close rendering bug on Safari on iOS 9.2.1. We receive a JSON object with a string in it. This string is copied by models contructors and then copied again the this model constructor is called as a cloner. The same string is bound to multiple objects and Safari does an optimization. This string is then breaking the renderer after multiple usages (more than 7). We detected the issue JavaScript side when reading the type of this string with We succeed in fixing the rendering issue by forcing the engine to de-optimize this string. We are going to find the less consuming way of forcing de-optimization but what works for now is: myObject.myString.split('').join(''); |
Hey, @atondelier thanks for that comment. I encountered the same issue with Safari 11 (macOS). The string value in an object was being changed by safari into a garbage value everywhere and your solution fixed it. Would this be a Safari bug? |
I found this issue that is absolutely imposible to debug for me. It happens like every other time so it's not clearly repeatable. As soon as I hook my iPad into remote debugging the issue disappears completely.
It seems to happen after a certain point of template complexity and nesting level. This can cause that the
name
attribute ininvokeAmbiguous
is"undefined"
. This of course crashes at the next callsetupHelpers
. Any idea what circumstances have to occur to have an outcome like that? I've already checked that the context and the template is fine.One of the possible templates where this can happen is:
Where the context is
There seems to be a Problem with
{{this}}
and it happens on the template call.First we thought that splitting the heavy nested stuff in Partials would fix the problem. But after a few hours it started again. We do not precompile our templates in node.js.
As I said - it's almost impossible to reproduce and to debug because it only happens in IOS Safari when it's not hooked to a debugging device like every other reload. Could it possible be a race condition or some memory issues?
EDIT: Stack Trace:
The text was updated successfully, but these errors were encountered: