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

The editor has encountered an unexpected error - Cannot read property 'rest_base' of undefined #9381

Closed
styledev opened this issue Aug 27, 2018 · 25 comments
Labels
[Status] Needs More Info Follow-up required in order to be actionable. [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@styledev
Copy link

styledev commented Aug 27, 2018

Describe the bug
When you create a new page and click [Publish...] for the first time I get an error/modal prompt that states: "The editor has encountered an unexpected error. [Attempt Recovery] [Copy Post Text] [Copy Error]"

The console shows the following error at the same time:

react-dom.min.82e21c65.js:110 TypeError: Cannot read property 'rest_base' of undefined
at index.js?ver=1534535888:12
at r (index.js?ver=1534535888:1)
at new e (index.js?ver=1534535888:1)
at yh (react-dom.min.82e21c65.js:97)
at lg (react-dom.min.82e21c65.js:120)
at mg (react-dom.min.82e21c65.js:120)
at gc (react-dom.min.82e21c65.js:127)
at vb (react-dom.min.82e21c65.js:126)
at ub (react-dom.min.82e21c65.js:126)
at wg (react-dom.min.82e21c65.js:137)

If you click [Attempt Recovery] the editor comes back and when you click [Publish...] the page will save. If you then change the page back to a draft, refresh the browser, and click [Publish...] you will get the error again.

TO NOTE: I just realized that if you open up the "Settings" (Shift + CMD + ,) and then click [Publish...] the page published as expected. It seems that the error stems from the Settings panel not being present. Works even if you close the settings then click [Publish...].

To Reproduce
Steps to reproduce the behavior:

  1. Go to Pages > Add New
  2. Fill in title and add some test content.
  3. Click the [Publish...] button
  4. See Error
  5. Click [Attempt Recovery] button
    6 Click [Publish] button
  6. Page saves
  7. Click the [x] next to "Published" in top right.
  8. Click [Switch to Draft]
  9. Reload page
  10. Go to Step “Select All” behavior #3 above.

Expected behavior
The expected behavior is for the page to be published and a green confirmation notice that says "Post published! View post"

Screenshots
Error: https://www.dropbox.com/s/coy9ekr51vciiiz/20180827-wordpress-4.9.8-gutenberg-v3.6.2-unexpected-error.png?dl=0

hjiizv2g

Desktop:

  • OS: MacOS High Sierra
  • Browser(s): Chrome 68.0.3440.106 (Official Build) (64-bit) | Safari Version 11.1.2 (13605.3.8) | FireFox 61.0.2 (64-bit)

Additional context
WordPress v. 4.9.8
Gutenberg v. 3.6.2
Safari and Firefox seem to state slightly different console error text.

@designsimply
Copy link
Member

Thank you for including clear details and a screenshot!

I am able to run Gutenberg 3.6.2 without error, so I believe the problem in your case may be due to a conflict with server settings or possibly a conflict with a plugin.

Are you able to temporarily turn off all other plugins and check to see if the error still happens? This will help rule out a plugin conflict.

I also noticed a similar-sounding error in #8802 where the problem turned out to be related to custom rewrite rules. Do you have anything like that setup on your web server which could be causing the trouble in this case?

@designsimply designsimply added [Type] Help Request Help with setup, implementation, or "How do I?" questions. [Status] Needs More Info Follow-up required in order to be actionable. labels Aug 27, 2018
@styledev
Copy link
Author

styledev commented Aug 27, 2018

@designsimply I should have stated that I am not running any other plugins and using the latest Twenty Seventeen theme.

The only other thing to note is I am running WordPress in it's own directory /wp/ so admin sits at /wp/wp-admin.

Though, I just did a fresh install of Wordpress 4.9.8 on it's own (regular install) with only the Gutenberg plugin installed and activated and I am getting the same error.

I made a recording of the issue > https://www.dropbox.com/s/so8hn1nbr3e18ue/Gutenberg%20Error.mov?dl=0

Update* I can reproduce this error on the live site > https://letsshareinc.org/

20180827-wordpress-4 9 8-gutenberg-v3 6 2-unexpected-error-live-site

@youknowriad
Copy link
Contributor

Looks like something related to the REST API, something (a plugin, a firewall, Cloudflare) is probably touching the REST API in the wrong way. I can't say more than that.

@styledev
Copy link
Author

@youknowriad The thing is I am not using any other plugins, I do not have a firewall, and aside from the live site there is no caching.

@youknowriad
Copy link
Contributor

Maybe a server config but I don't know. It would be good to find the source of this kind of issues though. Other persons might experience it and think Gutenberg is completely broken while it's not :)

Maybe you can try to dump the $preload_data in the client-assets.php file to see if there's anything wrong in the REST API responses?

@designsimply designsimply added Needs Testing Needs further testing to be confirmed. and removed [Status] Needs More Info Follow-up required in order to be actionable. labels Aug 28, 2018
@styledev
Copy link
Author

@youknowriad Here is a dump of $preload_data > https://gist.github.com/styledev/fccd3f996eec7b2033f8f541baacf8f0

Honestly, it looks like the culprit for all of this is that the settings sidebar does not exist if you load the page when the user has set the state of it to hidden. The initial "Add Page" load on a fresh install has the Settings sidebar shown and everything works fine. If you load in with out the Settings open then this issue occurs but if you click the Settings button first and then again to close it the issue does not happen.

@youknowriad
Copy link
Contributor

The preload data looks ok.

You're saying the issue happens when you open or close the sidebar. Can you monitor the network requests triggered when this happens and paste their responses here. (Essentially requests to /wp/v2/types/* and /wp/v2/taxonomies/*

@styledev
Copy link
Author

@youknowriad Have you watched the video I attached up above of the issue?

Reproduce Error

  • Fresh install click on Add New under Pages.
  • Settings sidebar is shown.
  • Click Settings cog icon to hide.
  • Refresh page and Settings sidebar is not shown
  • Add title and content click Publish... and this is where I get the error.

Error does not happen if you do:

  • Fresh install click on Add New under Pages.
  • Settings sidebar is shown.
  • Add title and content click Publish...
  • Page publishes

Error also does not happen if you do:

  • Fresh install click on Add New under Pages.
  • Settings sidebar is shown.
  • Click Settings cog icon to hide.
  • Refresh page and Settings sidebar is not shown
  • Add title and content click Settings cog to show Settings Sidebar
  • Click Settings cog to hide sidebar (optional)
  • Click Publish... and the page is published.

@youknowriad
Copy link
Contributor

Yes, but I can't reproduce personally.

@RickorDD
Copy link
Contributor

RickorDD commented Aug 29, 2018

i tested again without HTTPS and without plugins.
This is the SQL Query. Why is a "draft"?

Chrome:
bildschirmfoto 2018-08-29 um 20 25 49




and Safari shows not the Error Window only the Red Line.

Safari:
bildschirmfoto 2018-08-29 um 20 29 56

@RickorDD
Copy link
Contributor

RickorDD commented Aug 29, 2018

I found the Bug.
The Categories is not select. When i selected the Categories in Checkbox "Uncategorized" then not the error in Chrome and Safari.

bildschirmfoto 2018-08-29 um 20 45 42

@styledev
Copy link
Author

@RickorDD To note this issue was first reported by me in regards to Pages, not posts. Pages do not have categories. That said I defined SCRIPT_DEBUG as true and here is a better error from the unminified JS files in Gutenberg. I dug a little bit and seems to be an issue in the Vendor plugin http://www.jacklmoore.com/autosize/.

https://gist.github.com/styledev/c957fe8f56eca939ff88f7458d2ff409

screen shot 2018-08-29 at 12 19 12 pm

@youknowriad
Copy link
Contributor

This is just a warning, the real issue is the rest_base error. It seems like we're trying to access this property on a taxonomy or CPT object that's missing for some reason.

@styledev
Copy link
Author

@youknowriad Yeah, the issue has always been trying to access "rest_base" on an object that is undefined. If you have the Settings sidebar this error does not happen so it goes to reason that the object that "rest_base" is being called on is only defined if the Settings area has been initiated.

Please also note, while I am a programmer and have been learning React I have not been digging into the Gutenberg core code. I am just trying to support you on the error side. I hope everyone now has enough information. It is curious though that you can't recreate the error when I have no problem doing so both locally with a fresh WP and Gutenberg instance and on a production site.

@youknowriad
Copy link
Contributor

Please also note, while I am a programmer and have been learning React I have not been digging into the Gutenberg core code. I am just trying to support you on the error side. I hope everyone now has enough information.

I know and you're already helping a lot, I can now try "to guess" what might break. I'll plan to take a deeper look in the code soon and see if there's anything suspicious 🤷‍♂️ .

@RickorDD
Copy link
Contributor

RickorDD commented Aug 31, 2018

i tested again. I have changed the permalinks to "plain" and now is not a error.
But wenn i change to "Day and name" and create a new post than comes a blank screen.
I remember that there was a bug with similar phenomenon earlier.

bildschirmfoto 2018-08-31 um 12 36 09

@styledev
Copy link
Author

@RickorDD Changing my permalink structure to "Plain" did not solve this issue for me.

@Fathurhoho
Copy link

Fathurhoho commented Sep 2, 2018

I'm also experiencing same issue, Previously it was fine and I have made 2 articles with guttenberg. It seems getting conflict with Yoast SEO plugin, it works fine when i disabled Yoast SEO plugin.

  1. Screenshot: 2018-09-02_15h00_36
  2. Video: https://telegra.ph/file/b7641442669fff5e85022.mp4
  3. Log: https://gist.github.com/Fathurhoho/8bb35c1ff9b629855dcb2b4cf776e639

This happens when 'add new' and 'edit' any post.

  • Wordpress version: 4.9.8
  • Guttenberg version: 3.7.0
  • Yoast SEO plugin version: 8.1
  • Running in localhost

@designsimply
Copy link
Member

@styledev I tried testing this again today using a test site created at https://jurassic.ninja/ and could not see the error happen in my testing. I used these steps from one of your earlier comments:

Reproduce Error
  • Fresh install click on Add New under Pages.
  • Settings sidebar is shown.
  • Click Settings cog icon to hide.
  • Refresh page and Settings sidebar is not shown
  • Add title and content click Publish... and this is where I get the error.

I ran my test using WordPress 5.0.3 and no active plugins and I used Safari 12.0.3 on macOS 10.13.6.

9381-30s

Are you still seeing the "Cannot read property 'rest_base' of undefined" error after updating to the latest version of WordPress (5.0.3 at the time of this writing)?

Since you mentioned that you are not running any other plugins and that you used the latest Twenty Seventeen theme at the time of testing, I feel in that case it has got to be related to something in your server config… 🕵️‍♀️ are you able to try testing using https://jurassic.ninja/ as a check? Can you think of anything related to your server config or firewall that could have been blocking the REST API inadvertently?

@designsimply
Copy link
Member

@Fathurhoho thanks for chiming in! I see that the error from your video and screenshot is different than the one @styledev mentioned.

TypeError: Cannot read property 'getCollectionByRoute" of undefined

Just below your error, the wp-seo-post-scraper-810.min.js?ver=8.1:1 is mentioned, and that indicates that the problem in your case is potentially a conflict with the Yoast SEO plugin and I also saw that it was reported at Yoast/wordpress-seo#10867 and is now closed so I think that updating to the latest version of Yoast SEO should resolve the problem in your case!

@designsimply
Copy link
Member

@latereverafter there's not quite enough information to go on from the error you posted.

TypeError: Object(...) is not a function

First, can you update to the latest version of WordPress and also make sure that all of your plugins have been updated to their latest versions? If you're still having trouble after that, a good place to start will be to temporarily deactivate all active plugins and try the test again. If you're still seeing problems, please post all of the relevant details you've tried, note the latest version of WordPress you've tested with, and if possible include a copy/paste or a screenshot of the full error from the console panel in your browser's web developer tools to https://wordpress.org/support/forum/how-to-and-troubleshooting/ If you are not sure how to get the information needed for a bug report, the support forums are the very best place to ask for help with troubleshooting steps for that. Thank you!

@designsimply designsimply added [Status] Needs More Info Follow-up required in order to be actionable. and removed Needs Testing Needs further testing to be confirmed. labels Feb 12, 2019
@styledev
Copy link
Author

styledev commented Mar 5, 2019

Closing as this error is not present in the core version of Wordpress 5.

@styledev styledev closed this as completed Mar 5, 2019
@MWalid
Copy link

MWalid commented Jul 23, 2019

I have the same issue with gutenberg. It's not caused by yoast since it's been deactivated.

Leaving to classic editor for now!

@maharzan
Copy link

Similar thing was happening to me with WordPress 5.9 RC3. and changing permalinks to default helped. Tracking back to the issue, I found out that nginx.conf had this line

location / {
    try_files $uri $uri/ /index.php?$uri&args;
}

The $ was missing in args.. after I added $, the issue is resolved and there is no longer react dom error.

location / {
    try_files $uri $uri/ /index.php?$uri&$args;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] Needs More Info Follow-up required in order to be actionable. [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

8 participants