Skip to main content

Bug Tracker

Side navigation

#11795 closed feature (fixed)

Opened May 21, 2012 04:25PM UTC

Closed November 19, 2012 02:54PM UTC

Last modified March 20, 2013 12:04PM UTC

Resolve script manipulation/execution inconsistencies

Reported by: gibson042 Owned by: gibson042
Priority: high Milestone: 1.9
Component: manipulation Version: 1.7.2
Keywords: 1.9-discuss Cc:
Blocked by: Blocking:
Description

.domManip's treatment of <script>s is undocumented, inconsistent, and often counterintuitive. We should design a sane approach and document the hell out of it in all derived methods.

http://jsfiddle.net/jR3H6/1/

Special attention should be given to the following:

  • Breaking old code
  • Performance
  • Iteration (e.g., $("<div><a/><b/></div>").children().append("<script/>"))
Attachments (0)
Change History (21)

Changed May 21, 2012 04:26PM UTC by gibson042 comment:1

To get discussion started, I think we should never automatically detach elements. As for execution, I'd like to investigate the possibility of skipping it for scripts that already in the DOM before manipulation and just moving around.

Changed May 21, 2012 07:19PM UTC by dmethvin comment:2

I agree with this. See #3105 for some history though. I consider the liberal acceptance of <script> tags to be a security hole, it would have been nicer if we had a way for the user to explicitly say they wanted to run any scripts.

Changed May 22, 2012 10:29AM UTC by gibson042 comment:3

Issues like that are foremost in my mind. It's necessary to do ''something'' with scripts before dropping them in the DOM so we can prevent certain misbehaving browsers from executing them automatically, and it's also necessary to provide continuity with the past decision to execute them "once" as they land, but beyond that the landscape of possibilities is fairly open. The most important thing is having a productive discussion now to agree on and document a policy, hopefully one that will allow us to take further positive steps in the future.

Assuming that we'll still be running scripts through globalEval, and that we don't want to accidentally do so too often, I think we can meet the spirit of previous versions by assuming that anything already in the document has already been executed (and that there's no reason to execute anything until it actually hits the document). And if we're okay with ''re''-executing .detached scripts, we can accomplish it without any new _data or .clone issues or expensive code outside of domManip. Of course, "once and only once" is also possible if that's what we want.

To ease the transition, we might want to expose a convenience method that makes it easy to scrub a jQuery set... maybe a generalization of the input/script loops in jQuery.clean. Longer term, a flag controlling script execution is also a possibility.

Changed June 08, 2012 01:58AM UTC by dmethvin comment:4

#11878 is a duplicate of this ticket.

Changed June 08, 2012 02:00AM UTC by dmethvin comment:5

Once we decide what to do here, we need to document it. Our handling of scripts is undocumented, which is good since it's not a point of pride. :)

Changed June 26, 2012 01:39PM UTC by dmethvin comment:6

component: unfiledmanipulation
status: newopen

Changed August 23, 2012 04:08PM UTC by gibson042 comment:7

keywords: → 1.9-discuss

Changed September 09, 2012 01:11AM UTC by dmethvin comment:8

type: enhancementfeature

Bulk change from enhancement to feature.

Changed September 24, 2012 04:40PM UTC by dmethvin comment:9

I really need to see a plan of attack here before voting.

Changed September 27, 2012 11:50AM UTC by gibson042 comment:10

https://github.com/jquery/jquery/pull/864 is the working proof of concept, in which we mark in-document scripts as executed on detach, clone, clean, and domManip. It has a lot of oldIE code that I'll be happy to see go in 2.0.

Changed October 14, 2012 10:15PM UTC by mikesherov comment:11

this ticket seems like a "god ticket". for example, does #10470 fall under this?

Changed October 14, 2012 10:15PM UTC by mikesherov comment:12

+1, All for making this consistent, no matter the specifics.

Changed October 14, 2012 11:38PM UTC by gibson042 comment:13

Replying to [comment:11 mikesherov]:

this ticket seems like a "god ticket". for example, does #10470 fall under this?

I would say yes, even if the draft patch doesn't yet resolve it.

Changed October 15, 2012 05:39PM UTC by timmywil comment:14

priority: undecidedhigh

Changed October 16, 2012 05:08AM UTC by mikesherov comment:15

blocking: → 10470

Changed October 16, 2012 05:09AM UTC by mikesherov comment:16

blocking: 104709134, 10470

Changed October 22, 2012 05:16PM UTC by gibson042 comment:17

+1

Changed October 31, 2012 12:13AM UTC by mikesherov comment:18

milestone: None1.9

Changed October 31, 2012 03:43AM UTC by gibson042 comment:19

owner: → gibson042
status: openassigned

Changed November 19, 2012 02:54PM UTC by Richard Gibson comment:20

resolution: → fixed
status: assignedclosed

Fix #11795, #10470: keep scripts in DOM; execute only on first insertion. Close gh-864.

Changeset: e889134058232c5e19156353c5fc3bf3b4915a94

Changed March 20, 2013 12:04PM UTC by mikesherov comment:21

#13634 is a duplicate of this ticket.