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

Surface.View can not access context #647

Open
maennchen opened this issue Sep 5, 2022 · 0 comments
Open

Surface.View can not access context #647

maennchen opened this issue Sep 5, 2022 · 0 comments

Comments

@maennchen
Copy link
Contributor

maennchen commented Sep 5, 2022

Describe the bug

When using the context in a template defined inside a Surface.View, both (old) <Context get={...}> and (new) prop name, :type, from_context: ... in a used component yields nil.

How to reproduce it

  1. Use surface initialized with --layouts
  2. Use context in live.sface or a component used by live.sface
  3. Resulting value will always be nil

The behavior you expected

The value is read correctly.

Your Environment

Surface: v0.8.1
LiveView: v0.17.11
Elixir: v1.14.0

Culprit

I tracked down the issue to the following line:

initial_context =
if caller_is_module_component? do
quote do: @__context__
else
quote do: %{}
end

Since this looks like the context is intentionally set to an empty map, I decided not to attempt a PR for now.

Workaround

I built the component inclusion manually, for now, to work around the constraint / issue:

https://github.com/jshmrtn/hygeia/blob/c1debcb8c2652042ee1bf61b566ad2cb3e965ac7/lib/hygeia_web/templates/layout/live.sface#L2-L16

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

No branches or pull requests

1 participant