초기화 파일(initializer)에 다음 코드가 있습니다. allAdminRoutes의 getter를 오버라이드하려는 시도입니다:
api.modifyClass('controller:admin-plugins', {
pluginId: PLUGIN_ID,
get allAdminRoutes() {
return this.model
.filter((p) => p?.enabled)
.map((p) => {
return p.admin_route;
})
.filter(Boolean);
},
});
다음 오류가 발생하고 있습니다:
TypeError: this.model is undefined
사실 이 부분은 크게 문제가 되지 않을 수도 있지만, 현재 코드는 원래 getter 코드 와 동일합니다(아직 실제로 변경하지 않았거든요!)
무엇을 놓치고 있는 걸까요? 이 방식으로 getter를 오버라이드하는 것이 지원되지 않거나, 어떤 종류의 스코프 문제를 일으키는 걸까요?
4개의 좋아요
이상하게도 Latest에서는 문제가 아닌 것 같습니다. (그것은 Production에서 수행한 테스트였습니다.)
깨끗한 3.0.0 Stable 환경에서 재현해 볼 수 있는지 확인해 보겠습니다.
1개의 좋아요
david
(David Taylor)
1월 16, 2023, 10:38오전
4
예제는 정상적으로 작동해야 하며, 안정판 릴리스 이후 관련 변경 사항에 대해 인지하고 있지 않습니다. 문제를 재현할 수 있다면 알려 주세요!
1개의 좋아요
데이비드, 고마워. 그렇게 할게. 그래, 그 부분은 나도 알아챘어. 이 문제를 경험한 환경이 완전히 깨끗하지 않았기 때문에, 지금은 내가 먼저 확인해야 할 부분이 확실해.
1개의 좋아요
데이비드, 확인해보니 (좀 이상한데):
프로덕션에서는 동작함
3.0.0 버전부터 개발 환경에서는 실패함 (이전 버전에서도 그랬을 가능성 있음)
도커 없이 순수한 개발 환경에서도 테스트해봤고, 매우 깔끔하지만 (아마도 설정이 불완전할 수 있는) 맞춤형 도커 개발 환경에서도 테스트해봤음.
에러 내용은 다음과 같음:
Error occurred:
- While rendering:
-top-level
application
discourse-root
sidebar-wrapper
admin
admin-wrapper
nav-item
link-to
-link-to
Uncaught (in promise) TypeError: While generating link to route "adminPlugins": this.model is undefined
get allAdminRoutes admin-plugins.js:20
return this.model 이전에 디버거 문을 넣어도 디버거가 절대 트리거되지 않는다는 점에 유의해줘.
@RGJ 도 이 문제를 친절하게 살펴봐 주었고, 이 결과를 재현할 수 있다고 함.
이것은 분명히 프로덕션으로 배포하기 전에 개발을 해야 하므로 꽤 큰 문제인데 … 하지만 그건 당신에게 말하지 않아도 알겠지! 또한 스테이블 버전에서도 문제가 발생한다는 점이 좀 짜증남 …
일단 Contribute > Bug 로 옮겼음 …
2개의 좋아요
OK, 여기 문제가 있다는 것을 더 확신하게 되었습니다… 스택 트레이스에 mergeMixins가 언급되어 있기 때문이죠
opened 06:29PM - 03 Apr 20 UTC
closed 10:11PM - 11 Aug 26 UTC
Recently found an issue with mergeMixins. it affects Ember versions at least as … far back as 3.12 and also current release and LTS.
As I understand it, the issue is when a mixin defines a property (doesn’t necessarily have a value) then we try to access the value during construction before owner is set. This breaks getters that access services. Shared findings with @pzuraq.
Error message: `Attempting to lookup an injected property on an object without a container, ensure that the object was instantiated via a container. Error: Assertion Failed: Attempting to lookup an injected property on an object without a container, ensure that the object was instantiated via a container.`
[Code where issue arrises
](https://github.com/emberjs/ember.js/blob/v3.17.3/packages/@ember/-internals/metal/lib/mixin.ts#L475) (Please note: the original link was to `master` 😞. I've changed the tag to the version of ember published the day before, but I have no memory of the original code it linked to)
[Reproduction](https://ember-twiddle.com/3147343e2dbf0e4c6965a50fa7e7389d?openFiles=controllers.application%5C.js%2C) ([Gist](https://gist.github.com/nlfurniss/3147343e2dbf0e4c6965a50fa7e7389d))
(@RGJ 님이 이것을 찾아내 주셔서 감사합니다)
4개의 좋아요
david
(David Taylor)
1월 18, 2023, 5:57오후
10
좋은 발견 감사합니다. @merefield , @RGJ 님들께 감사드립니다.
Ember에서 발생하는 문제인 것 같다는 점을 언급하셨듯이, Discourse 내에서 이 문제를 해결할 수 있는 부분이 얼마나 될지 확신할 수 없습니다. 아마도 문제의 원인이 되는 메서드를 패치할 수 있을지도 모르겠습니다.
시작하기 위해, 진행 상황을 추적할 수 있도록 최소한의 실패 테스트 케이스를 추가했습니다. 테스트 내부의 주석에는 이 문제가 우리의 modifyClass 시스템에 의해 트리거되는 이유가 설명되어 있습니다:
main ← modify-class-getters
merged 10:41AM - 24 Jan 23 UTC
https://meta.discourse.org/t/251793/8
https://github.com/emberjs/ember.js/iss… ues/18860
4개의 좋아요
네, 당신도 수고 많으셨네요. 그 문제를 아직 해결하지 않은 게 좀 이상하네요. (Ember) 4.x에서 해결될지 알고 계신가요?
david
(David Taylor)
1월 18, 2023, 6:05오후
12
불행히도 Ember 4.x에서도 여전히 해당 문제가 존재하는 것 같습니다
1개의 좋아요
David Taylor:
최소 실패 테스트 케이스를 추가했습니다
유머러스하게도, Ember 프로젝트에서 관련 PR(아직 초안 상태)을 포함해 유일한 진전이 그것인 것 같습니다. 시간이 될 때 우선순위를 높여 처리해 달라고 정중하게 요청하는 것만으로 충분할지 궁금합니다:
main ← mixin-merging-18860
closed 03:41AM - 16 Dec 23 UTC
Our handling of getters and setters works correctly for cases where we have only… classic classes, or only native classes, or native classes extending classic classes. In some cases, however, it fails when we have "zebra-striping" of class types, with a classic class extending a native class which extends a (stack of) classic class(es). We correctly handle native getters in mixin and POJOs passed to `.extend()`, but—quite reasonably—do *not* handle getters on native classes when calling `.extend(SomeNativeClass)`. The result is that those getters are not decorated the way they are in mixins, so mixin merging ends up invoking the getter rather than defining a decorator which returns it.
Fixes #18860
이 이슈가 제3자 소속 직원이 의해 열렸다는 점은 충분히 이해하고 있습니다.
GitHub - emberjs/ember.js: Ember.js - A JavaScript framework for creating ambitious web applications · GitHub 에서 이슈를 제기하고 이 PR, 이 토픽, 그리고 여러분의 테스트를 참조하는 것이 가치가 있을까요?
david
(David Taylor)
1월 18, 2023, 10:06오후
14
네, 제 테스트는 그들의 테스트를 기반으로 하고 있습니다(다만 discourse 전용 api.modifyClass API를 사용하죠). 새로운 이슈를 여는 것은 적절하지 않다고 생각합니다. 이미 열린 이슈 와 100% 동일하니까요. 우선순위를 높일 수 있는 방법을 찾아보겠습니다.
3개의 좋아요
david
(David Taylor)
3월 2, 2023, 11:21오전
15
여기서 몇 가지 진전이 있습니다 - 이제 수정 사항이 포함된 PR이 [BUGFIX LTS] Don't run getters while applying mixins - Pull Request #20388 - emberjs/ember.js - GitHub 에서 열려 있습니다.
해당 PR이 병합되어 Ember 3.28로 백포트되면, Discourse에 최대한 빨리 적용할 계획입니다.
3개의 좋아요
백포트라니! 그게 궁금했는데, 정말 멋진 소식이에요!
이 작업을 이끌어 주셔서 감사합니다, David!
david
(David Taylor)
5월 5, 2023, 11:59오전
18
이 수정 사항은 Ember 3.28.12의 일부로 출시되었으며, 이를 사용하도록 Discourse를 업데이트 했습니다. 최신 Discourse로 업데이트한 후에도 modifyClass 관련 문제가 여전히 발생하면 알려 주시기 바랍니다.
6개의 좋아요
david
(David Taylor)
에 닫힘
5월 15, 2023, 7:00오전
20
이 주제는 9일 후 자동으로 닫혔습니다. 더 이상 새로운 답변을 남길 수 없습니다.