Title: nested component class lookup fails · Issue #181 · hyperstack-org/hyperstack · GitHub
Open Graph Title: nested component class lookup fails · Issue #181 · hyperstack-org/hyperstack
X Title: nested component class lookup fails · Issue #181 · hyperstack-org/hyperstack
Description: For example this test case will fail: it 'Looks up components in nested namespaces correctly' do mount 'Foo::Bar::Zoom' do module Foo module Bar class Zoom < HyperComponent render do Wham() end end end end module Wham end module Foo modu...
Open Graph Description: For example this test case will fail: it 'Looks up components in nested namespaces correctly' do mount 'Foo::Bar::Zoom' do module Foo module Bar class Zoom < HyperComponent render do Wham() end end...
X Description: For example this test case will fail: it 'Looks up components in nested namespaces correctly' do mount 'Foo::Bar::Zoom' do module Foo module Bar class Zoom < HyperComponent rende...
Opengraph URL: https://github.com/hyperstack-org/hyperstack/issues/181
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"nested component class lookup fails","articleBody":"For example this test case will fail:\r\n\r\n```ruby\r\n it 'Looks up components in nested namespaces correctly' do\r\n mount 'Foo::Bar::Zoom' do\r\n module Foo\r\n module Bar\r\n class Zoom \u003c HyperComponent\r\n render do\r\n Wham()\r\n end\r\n end\r\n end\r\n end\r\n\r\n module Wham\r\n end\r\n\r\n module Foo\r\n module Bar\r\n class Wham \u003c HyperComponent\r\n render(DIV) do\r\n \"found me!\"\r\n end\r\n end\r\n end\r\n end\r\n end\r\n expect(page).to have_content('found me!')\r\n end\r\n```\r\n\r\nThe problem is in the `lookup_const` method in the `Tags` module the `const_defined?` and `const_get` calls must include the second `false` parameter to prevent looking up the ancestor tree.\r\n\r\nYou can patch it like this:\r\n\r\n```ruby\r\nmodule Hyperstack\r\n module Internal\r\n module Component \r\n module Tags\r\n def lookup_const(name)\r\n return nil unless name =~ /^[A-Z]/\r\n scopes = self.class.name.to_s.split('::').inject([Object]) do |nesting, next_const|\r\n nesting + [nesting.last.const_get(next_const)]\r\n end.reverse\r\n scope = scopes.detect { |s| s.const_defined?(name, false) }\r\n scope.const_get(name, false) if scope\r\n end\r\n end\r\n end\r\n end\r\nend\r\n```\r\nFor the hyperloop legacy branch the same method is in\r\n```ruby\r\nmodule React\r\n module Component\r\n module Tags\r\n def lookup_const(name) \r\n ...\r\n end\r\n end\r\n end\r\nend\r\n```\r\n\r\nHowever this has a knock on effect that breaks hyper-model's INPUT tag redefinition. In that method redefinition the newly defined tag constants are made on the Tag module scope (incorrectly) and this bug allowed that to work. So that has to also be fixed, i.e. the new tags need to be defined against Object.\r\n\r\n","author":{"url":"https://github.com/catmando","@type":"Person","name":"catmando"},"datePublished":"2019-05-02T00:05:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/181/hyperstack/issues/181"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3a399d05-c4f4-6a27-e865-cd0a63ce1804 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A77C:14C083:776235:9765B0:69920BC3 |
| html-safe-nonce | ab5bb822f70fbd92eb02bd6b876e77980b0e0ef0291f8910ccc8454c93f5cb3c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzdDOjE0QzA4Mzo3NzYyMzU6OTc2NUIwOjY5OTIwQkMzIiwidmlzaXRvcl9pZCI6IjIwMjc0MTE4NDc1MzIxMjEwMjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a66d1bbd5aaa6b9b6c58a3d9d78abc804cd075e4bacf03942877f560fbf9160b |
| hovercard-subject-tag | issue:439379152 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/hyperstack-org/hyperstack/181/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fcb767e8bf7437d4cfab0fd41d5ad4079f0b561a01167cd825930acbe9d3cfd5/hyperstack-org/hyperstack/issues/181 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fcb767e8bf7437d4cfab0fd41d5ad4079f0b561a01167cd825930acbe9d3cfd5/hyperstack-org/hyperstack/issues/181 |
| og:image:alt | For example this test case will fail: it 'Looks up components in nested namespaces correctly' do mount 'Foo::Bar::Zoom' do module Foo module Bar class Zoom < HyperComponent render do Wham() end end... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | catmando |
| hostname | github.com |
| expected-hostname | github.com |
| None | 42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b |
| turbo-cache-control | no-preview |
| go-import | github.com/hyperstack-org/hyperstack git https://github.com/hyperstack-org/hyperstack.git |
| octolytics-dimension-user_id | 34562730 |
| octolytics-dimension-user_login | hyperstack-org |
| octolytics-dimension-repository_id | 145879576 |
| octolytics-dimension-repository_nwo | hyperstack-org/hyperstack |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 145879576 |
| octolytics-dimension-repository_network_root_nwo | hyperstack-org/hyperstack |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 848bc6032dcc93a9a7301dcc3f379a72ba13b96e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width