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

Bug: Editor fields not updating when linking between pages inside CMS #4147

Open
mcintyre321 opened this issue Aug 14, 2020 · 3 comments
Open

Comments

@mcintyre321
Copy link

I am using Netlify-CMS to build a readonly site, so I am using custom components which don't allow editing instead of the default ones.

One of those controls is a link to another-page-in-the-app control, which I'm using where one might ordinarily have a relation widget.

Describe the bug

When I follow the link to the linked page, any fields which have the same name as on the previous page are not updated.

To Reproduce

Expected behaviour
page is the same as if you have pasted the https://cuzkv.csb.app/#/collections/teams/entries/Some%20Team url into browser

Actual behaviour
The 'Name' field still says "Sentry"

Expected behavior
The 'Name' field says "Some Team"

Applicable Versions:

  • Netlify CMS version: [e.g. 2.0.4]
  • Git provider: repo-test
  • OS: Ubunut 20.04
  • Browser version chrome 83.0.4103.116 (Official Build) (64-bit)

https://codesandbox.io/s/cuzkv?file=/config.yml

Additional context

This is my custom widget. I wonder if I should be using a react router Link instead of an a but I don't know how to do that...

CMS.registerWidget(
        "relation-readonly",
        createClass({
          render: function () {
            return this.props.value
              ? h(
                  "a",
                  {
                    id: this.props.forID,
                    className: this.props.classNameWrapper,
                    href:
                      "#/collections/" +
                      this.props.field._root.entries[0][1] +
                      "/entries/" +
                      this.props.value
                  },
                  this.props.value
                )
              : h("span");
          }
        })
      );
@erezrokah
Copy link
Contributor

Hi @mcintyre321, I think the issue might be that we're loading the entry on component mount:
https://github.com/netlify/netlify-cms/blob/d649e960f0fa1d5b7ff5c0c306b8901e3ead87f2/packages/netlify-cms-core/src/components/Editor/Editor.js#L102
which might not happen when you link directly in the editor.
You could try using a react router Link component by setting up the widget as a separate package exporting a react component:
https://github.com/netlify/netlify-cms-widget-starter

Another option would be to add target="_blank" to open the entry in a new tab.

@mcintyre321
Copy link
Author

Hi, and thanks for your quick response.

I think this is technically a bug, the more I think about it. If I

  1. visit https://cuzkv.csb.app/#/collections/products/entries/Sentry
  2. paste the other url (https://cuzkv.csb.app/#/collections/teams/entries/Some%20Team) in to the address bar

I still get incorrectly displayed data, the Name field still says "Sentry" (so I don't think it's caused by my a tag).

@erezrokah
Copy link
Contributor

2. paste the other url (https://cuzkv.csb.app/#/collections/teams/entries/Some%20Team) in to the address bar

You'd need to do a refresh to make sure the component is remounted.

In order to fix it we would need to extract some of the code for loading the entry and registering the navigation blocker (https://github.com/netlify/netlify-cms/blob/d649e960f0fa1d5b7ff5c0c306b8901e3ead87f2/packages/netlify-cms-core/src/components/Editor/Editor.js#L123)

And run the relevant parts when the slug/collection changes.

@erezrokah erezrokah added type: bug code to address defects in shipped code status: confirmed good first issue and removed kind: question labels Aug 17, 2020
@erezrokah erezrokah changed the title Field not updating when linking between pages inside CMS bug: Editor fields not updating when linking between pages inside CMS Aug 17, 2020
@erezrokah erezrokah changed the title bug: Editor fields not updating when linking between pages inside CMS Bug: Editor fields not updating when linking between pages inside CMS Aug 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants