api.modifyClass가 가끔(!) 작동하지 않음

이를 버그로 재분류합니다.

플러그인 API 코드인 app/assets/javascripts/discourse/app/lib/plugin-api.js에 console.log를 추가하여 modifyClass가 호출될 때마다 로그를 기록하도록 했습니다.

어딘가에 충돌이 없는지 확인하기 위해 모든 외부 플러그인을 제거했습니다.

재현 방법:

  • stable에서 빈 포럼을 생성합니다(Ember CLI가 없는 상태). tests-passed(Ember CLI 없음)에서도 작동하지 않습니다. Ember CLI와 함께 테스트하지는 않았습니다.

  • 다음 내용을 Common - Head에 추가한 테마 컴포넌트를 추가합니다

#1 작동

<script type="text/discourse-plugin" version="0.1">
    api.modifyClass('model:user', {
      pluginId: 'test-tc',
      testFunction: function() {
        return 1;
      } 
    });
</script>
  • 홈 페이지를 로드합니다

  • 콘솔에 modifyClass called for model:user _application-08d9058ddd37ba80992f770509f4919ad0738a17f14fb85167b1dc1f32f8b56e.js:23490:16 Object { pluginId: "test-tc", testFunction: testFunction() }가 표시됩니다

  • 콘솔에 Discourse.currentUser.testFunction()을 입력합니다

  • "1"이 출력됩니다

#2 실패

  • 예를 들어 'Welcome to Discourse’와 같은 토픽으로 이동하여 페이지를 새로고침합니다
  • 콘솔에 동일한 “modifyClass called” 로그가 표시됩니다
  • 콘솔에 Discourse.currentUser.testFunction()을 입력합니다
  • Uncaught TypeError: Discourse.currentUser.testFunction is not a function가 출력됩니다

#3 경고와 함께 실패

  • 테마 컴포넌트 맨 위에 한 줄을 추가하여 다음과 같은 모양으로 만듭니다:
<script type="text/discourse-plugin" version="0.1">
    const userModel = api.container.lookup("model:user");

    api.modifyClass('model:user', {
      pluginId: 'test-tc',
      testFunction: function() {
        return 1;
      } 
    });

</script>
  • 예를 들어 'Welcome to Discourse’와 같은 토픽으로 이동하여 페이지를 새로고침합니다
  • 콘솔에 동일한 “modifyClass called” 로그가 표시됩니다
  • 콘솔에 경고 "model:user" was already cached in the container. Changes won't be applied.가 표시됩니다
  • 콘솔에 Discourse.currentUser.testFunction()을 입력합니다
  • Uncaught TypeError: Discourse.currentUser.testFunction is not a function가 출력됩니다

#4 작동

  • lookup 줄을 테마 컴포넌트 하단으로 이동하여 다음과 같은 모양으로 만듭니다:
<script type="text/discourse-plugin" version="0.1">
    api.modifyClass('model:user', {
      pluginId: 'test-tc',
      testFunction: function() {
        return 1;
      } 
    });

    const userModel = api.container.lookup("model:user");
</script>
  • 예를 들어 'Welcome to Discourse’와 같은 토픽으로 이동하여 페이지를 새로고침합니다
  • 콘솔에 동일한 “modifyClass called” 로그가 표시됩니다
  • 콘솔에 Discourse.currentUser.testFunction()을 입력합니다
  • "1"이 출력됩니다 :partying_face:
4개의 좋아요