You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I ran into a minor problem with the H5PPlayer. When the player opens, mergeH5PIntegration "[...] merge[s] the H5P integration we received from the server with the one that already exists in the window globally to allow for several H5P content objects on a single page." When this merge happens, the contents of core.styles and core.scripts are duplicated. This duplication happens each time the player renders.
This can be a problem because:
The arrays grow continuously (memory leak)
H5P.getHeadTags pulls directly from H5PIntegration.core and does not check for duplication
Scripts execute multiple times (can be problematic for editor and player customizations)
Steps to reproduce
Goto wherever your ContentList is rendered
Open and close the player a few times without reloading the page
With the player open, inspect the head tag within the player component to find duplicated script tags
Possible fix
deepmerge, the library used to merge objects, concatenates arrays by default; however, it supports customization for array merging. I was able to get everything working as expected by implementing the following:
Define that each item of an array should be merged (mostly a copy/paste from deepmerge documentation)
Detailed explanation
Hello, I ran into a minor problem with the H5PPlayer. When the player opens, mergeH5PIntegration "[...] merge[s] the H5P integration we received from the server with the one that already exists in the window globally to allow for several H5P content objects on a single page." When this merge happens, the contents of core.styles and core.scripts are duplicated. This duplication happens each time the player renders.
This can be a problem because:
H5PIntegration.core
and does not check for duplicationSteps to reproduce
ContentList
is renderedhead
tag within the player component to find duplicated script tagsPossible fix
deepmerge
, the library used to merge objects, concatenates arrays by default; however, it supports customization for array merging. I was able to get everything working as expected by implementing the following:The text was updated successfully, but these errors were encountered: