Last modified: 2013-11-11 19:28:06 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T54198, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 52198 - VisualEditor: Fix "Uncaught TypeError: Cannot read property 'params' of undefined 'content'"
VisualEditor: Fix "Uncaught TypeError: Cannot read property 'params' of undef...
Status: RESOLVED WORKSFORME
Product: VisualEditor
Classification: Unclassified
Data Model (Other open bugs)
unspecified
All All
: Unprioritized normal
: ---
Assigned To: Ed Sanders
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-07-28 18:48 UTC by Carl Fürstenberg
Modified: 2013-11-11 19:28 UTC (History)
4 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Carl Fürstenberg 2013-07-28 18:48:35 UTC
Per http://en.wikipedia.org/wiki/Wikipedia:VisualEditor/Feedback#Content_transclusion_causes_WTF_mode

If trying to add a template, only adding content (empty) and click apply, following error is thrown:

TypeError: content is undefined
http://bits.wikimedia.org/static-1.22wmf11/extensions/VisualEditor/modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js
Line 192
Comment 1 Krinkle 2013-07-28 21:06:43 UTC
1. Insert Transclusion
2. Ignore "New template" panel in the dialog and go to "+ [] Add content"
3. Type "x"
4. Apply changes
5. > Uncaught TypeError: content is undefined
http://bits.wikimedia.org/static-1.22wmf11/extensions/VisualEditor/modules/ve-mw/dm/nodes/ve.dm.MWTransclusionNode.js:192

>    ve.dm.MWTransclusionNode.prototype.getWikitext = function() {
>        var i, len, part, template, param, content = this.getAttribute('mw'), wikitext = '';
> >      if (content.params) {
>            content = {'parts': [{'template': content}]};
>        }

Uncaught TypeError: Cannot read property 'params' of undefined
ve.dm.MWTransclusionNode.getWikitext
ve.ce.MWTransclusionNode.generateContents
ve.ce.GeneratedContentNode.onUpdate
VeCeGeneratedContentNode
VeCeMWTransclusionNode
VeCeMWTransclusionInlineNode
ve.Factory.create
ve.ce.BranchNode.onSplice
ve.ce.ContentBranchNode.onSplice
oo.EventEmitter.emit
ve.dm.BranchNode.splice
ve.insertIntoArray
ve.dm.Document.rebuildNodes
ve.dm.DocumentSynchronizer.synchronizers.rebuild
ve.dm.DocumentSynchronizer.synchronize
ve.dm.TransactionProcessor.process
ve.dm.Document.commit
ve.dm.Surface.change
ve.dm.SurfaceFragment.insertContent
ve.ui.MWTransclusionDialog.onClose
ve.ui.Window.close
(anonymous function)
proxy
Comment 2 Carl Fürstenberg 2013-07-28 21:42:52 UTC
> > >      if (content.params) {

If we had used coffescript instead of plain JS, it would be so simple to write that as:
 if content?.params
   ...

Now I assume we'll need to do it manually as
  if (typeof content !== "undefined" && content !== null && content.params) {
    ...
  }
Comment 3 Roan Kattouw 2013-07-29 23:43:20 UTC
(In reply to comment #2)
> > > >      if (content.params) {
> 
> If we had used coffescript instead of plain JS, it would be so simple to
> write
> that as:
>  if content?.params
>    ...
> 
> Now I assume we'll need to do it manually as
>   if (typeof content !== "undefined" && content !== null && content.params) {
>     ...
>   }
It's much easier than that, you can just do if ( content && content.params ) . No need to use typeof and string comparisons and all that :)

Really, though, content shouldn't be undefined in the first place.
Comment 4 Krinkle 2013-11-11 18:58:22 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > > > >      if (content.params) {
> > 
> > If we had used coffescript instead of plain JS, it would be so simple to
> > write
> > that as:
> >  if content?.params
> >    ...
> > 
> > Now I assume we'll need to do it manually as
> >   if (typeof content !== "undefined" && content !== null && content.params) {
> >     ...
> >   }
> It's much easier than that, you can just do if ( content && content.params )
> .
> No need to use typeof and string comparisons and all that :)
> 
> Really, though, content shouldn't be undefined in the first place.

Indeed, guarding it with an if statement for content? itself is undesirable because the error is elsewhere.
Comment 5 Carl Fürstenberg 2013-11-11 19:07:02 UTC
Doesn't give a error anymore, but API is returning: 

 {"warnings":{"main":{"*":"Unrecognized parameter: 'token'"}},"visualeditor":{"result":"success","content":"<p>x</p>\n\n"}}
Comment 6 Krinkle 2013-11-11 19:27:05 UTC
(In reply to comment #1)
> 1. Insert Transclusion
> 2. Ignore "New template" panel in the dialog and go to "+ [] Add content"
> 3. Type "x"
> 4. Apply changes

5. Show changes
6. Review your changes

  Foo
+ x
  Bar

All works as expected on latest master, and no errors.
Comment 7 Krinkle 2013-11-11 19:28:06 UTC
(In reply to comment #5)
> Doesn't give a error anymore, but API is returning: 
> 
>  {"warnings":{"main":{"*":"Unrecognized parameter:
> 'token'"}},"visualeditor":{"result":"success","content":"<p>x</p>\n\n"}}

That warning is unrelated. We're passively passing the authentication token to API requests, even though some API requests don't require a token. This is technical debt we should clean up.

Closing bug as fixed/worksforme.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links