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

Resolve "nested layout" components #1596

Conversation

Windvis
Copy link
Collaborator

@Windvis Windvis commented Sep 10, 2023

This adds a new (failing) "nested-layout-components" scenario and the fix for it in a second commit.

Supersedes #1587 since it's not only a v2 addon issue.

@@ -565,6 +565,7 @@ export class Resolver {

private *componentJSCandidates(inPackageName: string) {
yield { prefix: '/components/', suffix: '' };
yield { prefix: '/components/', suffix: '/index' };
Copy link
Collaborator Author

@Windvis Windvis Sep 10, 2023

Choose a reason for hiding this comment

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

When I added a similar line to the componentTemplateCandidates generator method I ran into an issue with the v2 addon component. Something about not being allowed to call setComponentTemplate twice. My guess is that the v2 component is resolved twice in that scenario, since the extensions logic checks for both .js and .hbs files.

I haven't dug deeper to find the origins of the current setup. Adding it only here made the tests pass and I noticed yield { prefix: '/components/', suffix: '' }; wasn't added to componentTemplateCandidates either, which might be because of similar reasons?

This scenario tests that "nested layout" components work as expected under the "optimized" Embroider preset.
It seems these were no longer being resolved properly, resulting in error messages like this:

>  Module not found: Error: Can't resolve '#embroider_compat/components/name-of-nested-layout-component' in 'snip'
@Windvis Windvis force-pushed the fix/resolve-nested-layout-components branch from 0047b7d to 07aaa06 Compare September 10, 2023 15:16
Copy link
Collaborator Author

@Windvis Windvis Sep 10, 2023

Choose a reason for hiding this comment

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

Creating a new scenario adds a lot of extra CI jobs. Should I try to fit it in another scenario?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes please. If this fix is entirely in module-resolver.ts it can get tested in core-resolve-test.ts.

@Windvis Windvis added the bug Something isn't working label Sep 10, 2023
@ef4
Copy link
Contributor

ef4 commented Sep 10, 2023

Thanks for working on this.

I was guessing the fix for this would actually be at a slightly different spot. But I haven't dug in myself yet, so your solution may also be right.

Is the problematic case the one where componentJSCandidates() is called by tryReverseComponent() or is it the one where it's called by resolveComponent()? I think in resolveComponent() this fix would be superfluous because there the output is sent to nodeResolve, and that would necessarily handle index.js automatically.

If the problematic case happens only inside tryReverseComponent then the fix may be better inside that method.

I was also suspecting the problem could be in getEntryFromMergeMap(), because there we match over multiple candidate extensions but potentially should also include the index variant of each extension as well. If this is an issue for addon-provided components but not app-provided components, it's the mergeMap I'd expect to be the problem.

@Windvis
Copy link
Collaborator Author

Windvis commented Sep 11, 2023

Is the problematic case the one where componentJSCandidates() is called by tryReverseComponent() or is it the one where it's called by resolveComponent()? I think in resolveComponent() this fix would be superfluous because there the output is sent to nodeResolve, and that would necessarily handle index.js automatically.

As far as I can see, it's the resolveComponent code path where it goes wrong. nodeResolve does get called, but it tries to look up the app reexports of those addon components and they don't seem to be there when I check the folder locally.

For example, in the tests I added here it looks for app-template/components/v1-nested-layout-component in a tmp folder, so it should in theory look for the /index.* version as well, but that folder isn't there. It would then go to the fallbackResolve code path where the /index suffixed one does get found.

I was also suspecting the problem could be in getEntryFromMergeMap(), because there we match over multiple candidate extensions but potentially should also include the index variant of each extension as well. If this is an issue for addon-provided components but not app-provided components, it's the mergeMap I'd expect to be the problem.

Yea, I originally planned to do it like that, but then I saw that the componentJSCandidates method also had special handling for pod layouts and this seemed more in line with that.

In any case, it's probably going to take me a while to grasp the logic we're dealing with here, so no hard feelings if you would rather look into it yourself to find the real underlying issue 😄.

@lolmaus
Copy link
Collaborator

lolmaus commented Sep 13, 2023

@Windvis If you happen to need a strict mode test (as you mentioned in your previous PR), you can use this draft as a pattern, except enable the strict mode for an individual test case.

@ef4
Copy link
Contributor

ef4 commented Nov 7, 2023

I don't fully understand why this would be the correct place to fix this bug. /index is already implicitly allowed by nodeResolve. Maybe the bug here is really in the app-js matching?

We can use the test from here to debug it.

@Windvis
Copy link
Collaborator Author

Windvis commented Apr 30, 2024

Closing since I won't have the time to look into this again and it wasn't the correct fix anyways.

@Windvis Windvis closed this Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants