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

Convert addon to use template tag #84

Merged
merged 8 commits into from
Apr 18, 2023
Merged

Convert addon to use template tag #84

merged 8 commits into from
Apr 18, 2023

Conversation

simonihmig
Copy link
Contributor

@simonihmig simonihmig commented Mar 16, 2023

This converts all components of the addon itself (we only had this for the test-app before) to use template tags (gts).

@changeset-bot
Copy link

changeset-bot bot commented Mar 16, 2023

🦋 Changeset detected

Latest commit: 67a5169

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

This PR includes changesets to release 2 packages
Name Type
ember-headless-form Patch
docs-app 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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2023

Preview URLs

Env: preview
Docs: https://c8db88c8.ember-headless-form.pages.dev

@NullVoxPopuli
Copy link
Contributor

I just published 0.2.0 of the rollup plugin. I don't expect anything you've reported to be fixed, but i'll check this branch and see what's going on

@ynotdraw
Copy link
Contributor

YES!!!!! 🎉

@NullVoxPopuli
Copy link
Contributor

Glint / gts related type issues fixed here: #90
Looks like some real bugs are being revealed still!

and there are more work-arounds than I'm comfortable with in the types / imports -- I'll work towards fixing those

@NullVoxPopuli
Copy link
Contributor

The other reported issue has a fix PR here: emberjs/babel-plugin-ember-template-compilation#16 (though, I don't have sufficient context and that could throw a wrench in things 😅 )

@simonihmig
Copy link
Contributor Author

though, I don't have sufficient context and that could throw a wrench in things

Yeah, that's why I raised the issue first, without even trying to look into what needs to be fixed, as it seemed intentional for some reason. We'll see...

@simonihmig
Copy link
Contributor Author

Linting is fixed. But Embroider is broken, due to embroider-build/embroider#1382

@simonihmig
Copy link
Contributor Author

Linting is fixed. But Embroider is broken, due to embroider-build/embroider#1382

This is fixed now with embroider-build/embroider#1383. Therefore using a unstable release of Embroider now in our ember-try config, until we get the next stable release of Embroider!

@simonihmig simonihmig marked this pull request as ready for review April 14, 2023 10:36
Copy link
Contributor

@ynotdraw ynotdraw left a comment

Choose a reason for hiding this comment

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

🚀 This is awesome!

Copy link
Contributor

Choose a reason for hiding this comment

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

I love seeing these components in a single file! This is great.

Comment on lines +32 to +33
// this is copy pasted from https://github.com/emberjs/ember.js/blob/60d2e0cddb353aea0d6e36a72fda971010d92355/packages/%40ember/-internals/glimmer/lib/helpers/unique-id.ts
// Unfortunately due to https://github.com/emberjs/ember.js/issues/20165 we cannot use the built-in version in template tags
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh! This is good to know. Thanks for the helpful comment here

}

// eslint-disable-next-line @typescript-eslint/no-unused-vars -- workaround for unknown modifier helper: https://github.com/typed-ember/glint/issues/410
declare const modifier: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like a PR is up! typed-ember/glint#553 🎉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I saw that also. And it was merged some hours ago! 🎉

Comment on lines -11 to -27
import type TemplateRegistry from '@glint/environment-ember-loose/registry';

// importing this directly from the published types (https://github.com/embroider-build/embroider/blob/main/packages/util/index.d.ts) does not work,
// see point 3 in Dan's comment here: https://github.com/typed-ember/glint/issues/518#issuecomment-1400306133
declare class EnsureSafeComponentHelper<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
C extends string | ComponentLike<any>
> extends Helper<{
Args: {
Positional: [component: C];
};
Return: C extends keyof TemplateRegistry
? TemplateRegistry[C]
: C extends string
? ComponentLike<unknown>
: C;
}> {}
Copy link
Contributor

Choose a reason for hiding this comment

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

All of this cleanup is excellent 🎉

@simonihmig
Copy link
Contributor Author

Hey @camskene @joelamb @danwenzel, pulled you into this PR on a repo you might not have seen before, as Nicole (who together with Tony usually reviewed the stuff here) is out this week and I still need one more approval to be able to merge this! 😅. Would be nice if one of you could have a look, thanks!

<template>
<input
name={{@name}}
type="checkbox"

Choose a reason for hiding this comment

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

I'm surprised to see double quotes here, as we're now (sort of) in JS, and they were single quotes in the hbs... 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, didn't realise this before. Probably our prettier config is a bit inconsistent. I did wonder why we have single quotes in hbs before (which in other projects were usually double quotes)...

@@ -1,5 +1,6 @@
import Component from '@glimmer/component';
import { assert } from '@ember/debug';
import { on } from '@ember/modifier';

Choose a reason for hiding this comment

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

yay explicit imports! 🎉

export interface HeadlessFormControlRadioGroupComponentSignature {
Element: HTMLDivElement;
Args: {
// the following are private arguments curried by the component helper, so users will never have to use those

Choose a reason for hiding this comment

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

ah, I like this comment and the @internal syntax. I ran into this with a component recently and was wondering if there was good messaging like this

{{yield
(hash
Option=(component
HeadlessFormControlSelectOptionComponent selected=@value

Choose a reason for hiding this comment

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

don't need ensure-safe-component anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope! 🎉

With strict mode templates, the {{component}} helper is also more strict, not allowing a string based lookup anymore. This makes sense as you would have explicit imports anyway. And by that, Embroider can safely assume that whatever is passed to {{component myComponent}} as the first argument is already something that has been imported somewhere (and as such it is already "seen" by Embroider/webpack and added to the bundle), so it does not need to care about this being potentially unsafe anymore. I also learned about this more recently...

@simonihmig simonihmig merged commit dd97c0b into main Apr 18, 2023
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