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

Small tweaks from ongoing backwards compatibility struggle in plugins #1139

Merged
merged 2 commits into from
Feb 15, 2024

Conversation

piemonkey
Copy link
Contributor

Overview

Don't crash if we use a toolbar button for a mark that isn't in the schema and give some more fine-grained output when blackbox tests fail.

connected issues and PRs:

N/A

Setup

N/A

How to test/reproduce

Remove a mark (such as redacted from the schema but leave the corresponding toolbar button in place, you should get a nice console log telling you what's wrong and the button should just be disabled (it used to crash).
Enable one of the failing blackbox tests and see the slightly improved failure message.

Challenges/uncertainties

N/A

Checks PR readiness

  • UI: works on smaller screen sizes
  • UI: feedback for any loading/error states
  • Check cancel/go-back flows
  • Check database state correct when deleting/updating (especially regarding relationships)
  • changelog
  • npm lint
  • no new deprecations

@@ -8,25 +9,38 @@ type Args = {
mark: string;
};
export default class MarkComponent extends Component<Args> {
constructor(owner: unknown, args: Args) {
if (!args.controller?.schema.marks[args.mark]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!args.controller?.schema.marks[args.mark]) {
if (!args.controller.schema.marks[args.mark]) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This suggestion would just cause it to fail to start as args.controller will be undefined. I'll tweak this to not log on startup. I don't really want to change the way this is used just for this convenience log to work correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

True, but then we should also adjust the argument types to mark the controller argument as optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, this is tricky. In this kind of context, TS assumes that your code is obeying the types, which in a pure TS codebase should (but won't always) be true. At the very least, there should be an error when you misuse something. With a mixture of TS and JS or TS and handlebars, this is no longer true.

I don't think we should change the arguments as while it no longer should crash if controller is not supplied, the class is useless if it isn't. I can't think of a good way to, within this class body, treat Args as partial, but keep the members of Args as required. Just marking get controller() as returning SayController | undefined for example does not seem to work.

Copy link
Member

@abeforgit abeforgit Feb 19, 2024

Choose a reason for hiding this comment

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

why would controller be undefined?
that would mean the parent component is passing in an incorrect value, so crashing is totally fine.
Sure, you'd like a build-time warning which we lose because we pass through unchecked templates (we'll get it back when we can enable glint), but that doesn't change how we should design the component imo.
Either you support the flexibility, and type it as optional, and nullcheck yourself, or you don't, and require the calling component to make sure its not passing in undefined.

Copy link
Contributor

@elpoelma elpoelma left a comment

Choose a reason for hiding this comment

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

Looks good to me overall! It just seems that the console log shows up a lot, because the controller argument is not passed yet (is still undefined) when constructing the mark-buttons.
Two possible solutions to this:

  • Make the controller argument of the buttons non-optional and only instantiate the buttons when the controller is defined
  • Move the schema check out of the controller into the mark getter and only check the existance of the mark/node-spec in the schema once the controller is defined.

@piemonkey piemonkey merged commit 00c510f into feat/rdfa-links-ui Feb 15, 2024
3 of 4 checks passed
@piemonkey piemonkey deleted the fix/test-tweaks branch February 15, 2024 15:30
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.

3 participants