Closed
Description
What problem does this feature solve?
In vue-server-renderer
, the renderState()
method generates a <script>
tag in which the context state is injected for client consumption and hydration. Both the contextKey
and windowKey
are configurable via options, but there is no way to customize the <script>
tag for targeting purposes.
I would like to be able to remove this <script>
tag from the DOM after client hydration, but it would be very hacky to find and select this node without the ability to define an id
attribute or similar on it. I am proposing a new option that will append an id
attribute to this <script>
tag, called scriptKey
. This new scriptKey
should be in the same options object that contextKey
and windowKey
are currently.
What does the proposed API look like?
context.renderState({
scriptKey: 'VueState'
});
// -> <script id="VueState">window.__INITIAL_STATE__={...}</script>
so that later in the client code this is possible:
const vueTag = document.getElementById('VueState');
vueTag.parentElement.removeChild(vueTag);