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

fix custom views setter issue #5586

Merged
merged 4 commits into from
May 3, 2021

Conversation

gautamsi
Copy link
Member

@gautamsi gautamsi commented May 2, 2021

found issue when trying to use custom views, it gives this error Cannot set property Field of #<Object> which has only a getter

image

I was able to fix this using this change, not sure if this is best way to do this. I could not find any other way.

@changeset-bot
Copy link

changeset-bot bot commented May 2, 2021

🦋 Changeset detected

Latest commit: ce5e786

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@keystone-next/admin-ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented May 2, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/keystonejs/keystone-next-docs/9e5CGFARun1vk7J4NJoSffFqx4cu
✅ Preview: https://keystone-next-git-fork-gautamsi-error-in-custom-view-ke-eea863.vercel.app

@vercel vercel bot temporarily deployed to Preview May 2, 2021 23:40 Inactive
@@ -93,7 +93,7 @@ export function useAdminMeta(adminMetaHash: string, fieldViews: FieldViews) {
);
}
});
const views = fieldViews[field.viewsIndex];
const views = { ...fieldViews[field.viewsIndex] };
Copy link
Member Author

@gautamsi gautamsi May 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not trace why this views has Field property as getter only, best way would be to make sure this allows setter, but this is quick fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you show an example of how you defined your custom field views? I'd like to try to recreate this so we can get to the root cause of the bug.

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 2, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ce5e786:

Sandbox Source
@keystone-next/example-sandbox Configuration

@vercel vercel bot temporarily deployed to Preview May 3, 2021 02:26 Inactive
@vercel vercel bot temporarily deployed to Preview May 3, 2021 02:31 Inactive
Copy link
Member

@JedWatson JedWatson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out this is happening because the module exports are special, and we need to turn it into a plain object to overwrite the built-in views with custom ones.

This fix may not be the most elegant solution (cc/ @mitchellhamilton) but verified it works for now.

Glad you picked it up @gautamsi and thanks for the PR! the fix will go out with the release today.

I've added back in an example (otherwise commented out) so this can be more easily tested, and will open a separate PR later with an actual example project demoing and testing this functionality.

@JedWatson JedWatson enabled auto-merge (squash) May 3, 2021 02:34
@JedWatson JedWatson merged commit dbc62ff into keystonejs:master May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants