surface-ui / surface

A server-side rendering component library for Phoenix
https://surface-ui.org
MIT License
2.08k stars 150 forks source link

`Surface.View` can not access context #647

Open maennchen opened 2 years ago

maennchen commented 2 years ago

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: https://github.com/surface-ui/surface/blob/b9675f9662f9d684ad4baeebdcc358ffab5264b2/lib/surface/compiler/eex_engine.ex#L1095-L1100

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