title: Upgrade react-admin v2 to v3, permissions is always empty and context is not consistent
body: <p>I am stuck in a react-admin <code>v2</code> to <code>v3</code> upgrade with two weird issues while I was wrapping the <code>layout</code> like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>  composeLayout(Layout) {
      const ComponentLayout = ({ references, dispatch, ...props }) =&gt; ( // eslint-disable-line no-unused-vars
        &lt;WithPermissions
          // eslint-disable-next-line no-unused-vars
          render={({ permissions }) =&gt; (
            &lt;AppContextProvider
              permissions={permissions}
              references={references} 
            &gt;
              &lt;Layout {...props} /&gt;
            &lt;/AppContextProvider&gt;
          )}
        /&gt;
      );
  
      const mapStateToProps = (state) =&gt; {
        const references = {};
        Object.keys(state.admin.resources).forEach((name) =&gt; {
          set(references, `${camelizePath(name)}.name`, name);
        });
        return { references };
      };
      return connect(mapStateToProps)(ComponentLayout);
    }
  </code></pre>
  
  <ul>
  <li><code>references</code> is correctly set but always empty object when reading it from the context afterward</li>
  <li><code>permissions</code> is always <code>undefined</code>, while <code>authProvider.getPermissions()</code> always return a non empty array of permission.</li>
  </ul>
  
  <p>This is the view within the debugger, it shows passed values to <code>AppContextProvider</code>, we see that <code>permissions</code> is <code>undefined</code> and <code>references</code> not empty:</p>
  
  <p><a href="https://i.stack.imgur.com/KfzYS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KfzYS.png" alt="enter image description here"></a></p>
  
  <p>This screenshot show what's in the context when we try to read from it, we can see that <code>references</code> is now an empty object:</p>
  
  <p><a href="https://i.stack.imgur.com/sZhJq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sZhJq.png" alt="enter image description here"></a>
  It was working fine in react-admin v2.</p>
  
  <p>Our goal is to:</p>
  
  <ul>
  <li>use references from a references object instead of writing hard references everywhere in our app.</li>
  <li>create a <code>pages</code> object that depends on user's permissions for the app so we do not write hard links everywhere in the app.</li>
  </ul>
  
  <p>What did change recently that could cause such strange behavior in v3?</p>