-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Customize server state script tag #6761
Comments
This is a good idea, but instead of exposing the option just for the id, why not just expose an option to make the script self-removing? I even think it should be removed by default and only turned on during development. |
Even better! Shall I work on a PR for that then? |
@markbrouch yes please! |
Well, now that I think about it, this One thing we could do is provide the boolean option |
The script registers the global variable |
Oh I see what you're getting at - we can have the script tag delete itself immediately since it will have already dumped |
Enable intial state script to automatically remove itself from the DOM if server environment is prod. vuejs#6761
Wrap auto-remove script in IIFE so that global scope is not polluted. vuejs#6761
What problem does this feature solve?
In
vue-server-renderer
, therenderState()
method generates a<script>
tag in which the context state is injected for client consumption and hydration. Both thecontextKey
andwindowKey
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 anid
attribute or similar on it. I am proposing a new option that will append anid
attribute to this<script>
tag, calledscriptKey
. This newscriptKey
should be in the same options object thatcontextKey
andwindowKey
are currently.What does the proposed API look like?
so that later in the client code this is possible:
The text was updated successfully, but these errors were encountered: