-
Notifications
You must be signed in to change notification settings - Fork 516
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
fix(panel): append panel body as a child element #3561
Conversation
@@ -21,37 +21,40 @@ storiesOf('Panel', module) | |||
}) | |||
) | |||
.add( | |||
'with ratingMenu', | |||
'with range input', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated these stories because they conflicted with the playground.
Deploy preview for instantsearchjs ready! Built with commit e6057c3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add a test about the actual issue, the fact that the widget was unmount/mount at each render.
As expected, this added an extra div between the body and the widget root. I think it's a reasonable tradeoff in this case, although I wonder if there might be another way |
@samouss Any clue what would be a good way to test this? It seems to be very specific to Preact, and especially this current version. I'm not sure it would make sense to test that since the test can break if we upgrade the Preact dependency someday. (I added a test on the lifecycle but it's unrelated) @Haroenv We could mount the widget in a |
@francoischalifour I don't think it's an issue, it might be an expected behaviour. Indeed it's very specific to Preact like the issue we have. IMO it worth cover it with a test to avoid any regression in the future. We can reproduce the exact same logic that we have inside the Panel and test that the component is not re-created. |
53ba199
to
e6057c3
Compare
FYI we decided not to test #3561 (comment). This will be fixed by Preact X. |
@@ -112,18 +111,19 @@ export default function panel({ | |||
|
|||
const renderPanel = renderer({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove the indirection created by the renderer
. We can avoid to return a new function from the renderer and provide the full list of argument each time call the function. We do this in widgets because we don't have the control on the render
call (which can be avoided anyway). Here we do have the control (see below). We can do it in another PR.
const renderer = ({
containerNode,
bodyContainerNode,
cssClasses,
templateProps,
options,
hidden
}) => {
render(
<Panel
cssClasses={cssClasses}
hidden={hidden}
templateProps={templateProps}
data={options}
bodyElement={bodyContainerNode}
/>,
containerNode
);
};
## [3.2.1](v3.1.0...v3.2.1) (2019-03-18) ### Bug Fixes * **connectToggleRefinement:** keep user provided, but falsy values ([#3526](#3526)) ([958a151](958a151)) * **instantsearch:** update usage errors ([#3543](#3543)) ([a2a800b](a2a800b)) * **panel:** append panel body as a child element ([#3561](#3561)) ([3de59a3](3de59a3)) * **poweredBy:** remove TypeScript extension in import ([#3530](#3530)) ([99ecc0b](99ecc0b)), closes [#3528](#3528) * **release:** update doctoc script ([e07c654](e07c654)) * **searchbox:** unmount component on dispose ([#3563](#3563)) ([c3f0435](c3f0435)) * **searchBox:** add reusable SearchBox component ([#3489](#3489)) ([c073a9a](c073a9a)) ### Features * **panel:** implement collapsed feature ([#3575](#3575)) ([e84b02b](e84b02b))
Summary
There's an issue where Preact loses the
bodyRef
ref when the widget re-renders because it cleans the tree. This issue exists with bothpreact
andpreact-compat
(version <10.0.0
) but not withreact
(tested by @samouss).This problem makes the collapsible option impossible to implement in the panel. It also causes other issues:
The input range width loses the reference of its container.
Result
This solution doesn't rely on
ref
s but on plain DOM manipulation. It inserts the body when the Preact component is mounted.Note that this solution inserts another
div
insidediv.ais-Panel-body
(this is a recurring issue encountered in the GeoSearch component for example without big consequences).