apsavin / bnsf

bem node single page application framework
MIT License
43 stars 4 forks source link

Sometimes BEM context is undefined during page generation #38

Closed jifeon closed 9 years ago

jifeon commented 9 years ago

How to reproduce:

Suppose I have a page and a block inside it. Here is bemhtml for the block:

block('entity')(
    elem('label')(
        tag()('span')
    ),

    elem('short-description')(
        tag()('span'),

        match(this.ctx.shortInfo)(
            content()(function () {
                return ' - ' + this.ctx.shortInfo;
            })
        )
    )
);

It fails with error

Error process page /backbonex/backbone.view.elements GET TypeError: Cannot read property 'shortInfo' of undefined
    at BEMContext.templates (/home/jifeon/projects/adwiki__front/bundles/index/index.bemhtml.js:1103:23)
    at run (/home/jifeon/projects/adwiki__front/bundles/index/index.bemhtml.js:165:13)
    at BEMContext.<anonymous> (/home/jifeon/projects/adwiki__front/bundles/index/index.bemhtml.js:114:14)
    at bodyHandler (/home/jifeon/projects/adwiki__front/bundles/index/index.bemhtml.js:92:54)
    at apply (/home/jifeon/projects/adwiki__front/bundles/index/index.bemhtml.js:113:40)
    at bemApply (/home/jifeon/projects/adwiki__front/bundles/index/index.bemhtml.js:363:20)
    at BEMContext.ctx (/home/jifeon/projects/adwiki__front/bundles/index/index.bemhtml.js:704:13)
    at run (/home/jifeon/projects/adwiki__front/bundles/index/index.bemhtml.js:173:15)
    at BEMContext.<anonymous> (/home/jifeon/projects/adwiki__front/bundles/index/index.bemhtml.js:114:14)
    at bodyHandler (/home/jifeon/projects/adwiki__front/bundles/index/index.bemhtml.js:92:54)

Of course there is a workaround: just match this.ctx && this.ctx.shortInfo, but there is nothing about it in the bem docs, and I think it's because ctx must be defined every time.

Error appears during page block generation.

apsavin commented 9 years ago

https://github.com/bem/bem-core/issues/736