Skip to content

Surface.View can not access context #647

Open

Description

@maennchen

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions